@uidu/client 3.18.0 → 3.20.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 +26 -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 +503 -0
- package/dist/declarations/src/expenses.d.ts +5 -0
- package/dist/declarations/src/field-values.d.ts +34 -0
- package/dist/declarations/src/generated/index.d.ts +12104 -4367
- 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 +469 -31
- package/dist/uidu-client.cjs.prod.js +469 -31
- package/dist/uidu-client.esm.js +433 -32
- package/package.json +1 -1
- package/src/calls.ts +37 -0
- package/src/candidates.ts +105 -0
- package/src/contracts.test.ts +97 -0
- package/src/contracts.ts +139 -0
- package/src/field-values.ts +95 -0
- package/src/generated/index.ts +841 -343
- package/src/index.ts +63 -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/ContractMutations.graphql +108 -0
- package/src/queries/contracts/ContractQueries.graphql +84 -0
- package/src/queries/courses/CourseMutations.graphql +0 -13
- package/src/queries/discardable/DiscardableMutations.graphql +32 -0
- package/src/queries/expenses/ListAnalyticAccounts.graphql +4 -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
package/package.json
CHANGED
package/src/calls.ts
CHANGED
|
@@ -3,15 +3,32 @@ import {
|
|
|
3
3
|
GetCallDocument,
|
|
4
4
|
type GetCallQuery,
|
|
5
5
|
type GetCallQueryVariables,
|
|
6
|
+
ListCallStatusesDocument,
|
|
7
|
+
type ListCallStatusesQuery,
|
|
8
|
+
type ListCallStatusesQueryVariables,
|
|
6
9
|
ListCallsDocument,
|
|
7
10
|
type ListCallsQueryVariables,
|
|
8
11
|
} from './generated';
|
|
12
|
+
import { paginate } from './utils/paginate';
|
|
9
13
|
import { nodes } from './utils/relay';
|
|
10
14
|
|
|
11
15
|
export type Call = NonNullable<
|
|
12
16
|
NonNullable<GetCallQuery['currentWorkspace']>['call']
|
|
13
17
|
>;
|
|
14
18
|
|
|
19
|
+
/** One stage of a call's pipeline — what `Application.status` points at. */
|
|
20
|
+
export type CallStatus = NonNullable<
|
|
21
|
+
NonNullable<
|
|
22
|
+
NonNullable<
|
|
23
|
+
NonNullable<
|
|
24
|
+
NonNullable<
|
|
25
|
+
NonNullable<ListCallStatusesQuery['currentWorkspace']>['call']
|
|
26
|
+
>['statuses']
|
|
27
|
+
>['edges']
|
|
28
|
+
>[number]
|
|
29
|
+
>['node']
|
|
30
|
+
>;
|
|
31
|
+
|
|
15
32
|
/**
|
|
16
33
|
* One call (a job opening or open call) with its application `form`, same
|
|
17
34
|
* shape as `getForm`, or null.
|
|
@@ -35,3 +52,23 @@ export async function listCalls(
|
|
|
35
52
|
const result = await client.query(ListCallsDocument, variables);
|
|
36
53
|
return nodes(result.currentWorkspace?.calls);
|
|
37
54
|
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The pipeline of a call: the statuses its applications move through, sorted
|
|
58
|
+
* by `position`, walking all pages. Move an application along it with
|
|
59
|
+
* `updateApplication` (`attributes.statusId`). Requires a Bearer token.
|
|
60
|
+
*/
|
|
61
|
+
export async function listCallStatuses(
|
|
62
|
+
client: UiduClient,
|
|
63
|
+
variables: Omit<ListCallStatusesQueryVariables, 'after'>,
|
|
64
|
+
): Promise<CallStatus[]> {
|
|
65
|
+
const statuses = await paginate(client, ListCallStatusesDocument, {
|
|
66
|
+
variables: { first: 100, ...variables },
|
|
67
|
+
extract: (data) => data.currentWorkspace?.call?.statuses,
|
|
68
|
+
});
|
|
69
|
+
return statuses.sort(
|
|
70
|
+
(a, b) =>
|
|
71
|
+
(a.position ?? Number.MAX_SAFE_INTEGER) -
|
|
72
|
+
(b.position ?? Number.MAX_SAFE_INTEGER),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreatePoolContactDocument,
|
|
4
|
+
type CreatePoolContactMutationVariables,
|
|
5
|
+
FindCandidatesDocument,
|
|
6
|
+
type FindCandidatesQuery,
|
|
7
|
+
type FindCandidatesQueryVariables,
|
|
8
|
+
GetCandidateDocument,
|
|
9
|
+
type GetCandidateQuery,
|
|
10
|
+
type GetCandidateQueryVariables,
|
|
11
|
+
ListPoolsDocument,
|
|
12
|
+
type ListPoolsQuery,
|
|
13
|
+
type ListPoolsQueryVariables,
|
|
14
|
+
UpdateCandidateDocument,
|
|
15
|
+
type UpdateCandidateMutationVariables,
|
|
16
|
+
} from './generated';
|
|
17
|
+
import { nodes } from './utils/relay';
|
|
18
|
+
|
|
19
|
+
// Candidates are the people in a workspace's talent pool: a `Candidate` wraps
|
|
20
|
+
// the person's `user` and `contact` with their pool consent and retention.
|
|
21
|
+
// `Pool`s group contacts (a `PoolContact` is one contact in one pool).
|
|
22
|
+
//
|
|
23
|
+
// Everything here holds private personal data: reads and writes need an
|
|
24
|
+
// account (Bearer / apiKey), server-side.
|
|
25
|
+
|
|
26
|
+
export type CandidateSearch = NonNullable<
|
|
27
|
+
NonNullable<FindCandidatesQuery['currentWorkspace']>['findCandidates']
|
|
28
|
+
>;
|
|
29
|
+
export type Candidate = CandidateSearch['candidates'][number];
|
|
30
|
+
export type CandidateDetail = Extract<
|
|
31
|
+
NonNullable<GetCandidateQuery['node']>,
|
|
32
|
+
{ __typename: 'Candidate' }
|
|
33
|
+
>;
|
|
34
|
+
export type Pool = NonNullable<
|
|
35
|
+
NonNullable<
|
|
36
|
+
NonNullable<
|
|
37
|
+
NonNullable<ListPoolsQuery['currentWorkspace']>['pools']['edges']
|
|
38
|
+
>[number]
|
|
39
|
+
>['node']
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Rank the talent pool against a description (`term`) — and, with `callId`,
|
|
44
|
+
* that call's applications too — and return the `candidates`, `applications`
|
|
45
|
+
* and per-record `evidence`, or null when the viewer may not search.
|
|
46
|
+
*
|
|
47
|
+
* This is the only way to list candidates: the workspace has no plain
|
|
48
|
+
* `candidates` connection. A blank `term` with a `callId` uses the call's own
|
|
49
|
+
* words; `near` + `withinKm` keep only those living close enough, and
|
|
50
|
+
* `eligibleFor` only those of an age the contract allows.
|
|
51
|
+
*/
|
|
52
|
+
export async function findCandidates(
|
|
53
|
+
client: UiduClient,
|
|
54
|
+
variables: FindCandidatesQueryVariables = {},
|
|
55
|
+
): Promise<CandidateSearch | null> {
|
|
56
|
+
const result = await client.query(FindCandidatesDocument, variables);
|
|
57
|
+
return result.currentWorkspace?.findCandidates ?? null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* One candidate by GlobalID, with their applications and the pools they are
|
|
62
|
+
* in, or null.
|
|
63
|
+
*/
|
|
64
|
+
export async function getCandidate(
|
|
65
|
+
client: UiduClient,
|
|
66
|
+
variables: GetCandidateQueryVariables,
|
|
67
|
+
): Promise<CandidateDetail | null> {
|
|
68
|
+
const result = await client.query(GetCandidateDocument, variables);
|
|
69
|
+
const node = result.node;
|
|
70
|
+
return node?.__typename === 'Candidate' ? (node as CandidateDetail) : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Update a candidate: pool consent (`poolConsentAt`), `source`, or
|
|
75
|
+
* `extendRetention: true` to push `retainUntil` out by another retention
|
|
76
|
+
* period. Returns the mutation payload as-is (including any `errors`).
|
|
77
|
+
*/
|
|
78
|
+
export async function updateCandidate(
|
|
79
|
+
client: UiduClient,
|
|
80
|
+
variables: UpdateCandidateMutationVariables,
|
|
81
|
+
) {
|
|
82
|
+
const result = await client.mutate(UpdateCandidateDocument, variables);
|
|
83
|
+
return result.updateCandidate ?? null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The workspace's talent pools with how many contacts each holds; page with `first`/`after`. */
|
|
87
|
+
export async function listPools(
|
|
88
|
+
client: UiduClient,
|
|
89
|
+
variables: ListPoolsQueryVariables = {},
|
|
90
|
+
): Promise<Pool[]> {
|
|
91
|
+
const result = await client.query(ListPoolsDocument, variables);
|
|
92
|
+
return nodes(result.currentWorkspace?.pools);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Add a contact to a pool (`attributes: { poolId, contactId }`). Returns the
|
|
97
|
+
* mutation payload as-is (including any `errors`).
|
|
98
|
+
*/
|
|
99
|
+
export async function createPoolContact(
|
|
100
|
+
client: UiduClient,
|
|
101
|
+
variables: CreatePoolContactMutationVariables,
|
|
102
|
+
) {
|
|
103
|
+
const result = await client.mutate(CreatePoolContactDocument, variables);
|
|
104
|
+
return result.createPoolContact ?? null;
|
|
105
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
const request = vi.fn();
|
|
4
|
+
|
|
5
|
+
vi.mock('graphql-request', () => ({
|
|
6
|
+
GraphQLClient: class {
|
|
7
|
+
request = request;
|
|
8
|
+
},
|
|
9
|
+
ClientError: class extends Error {},
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const { createClient } = await import('./client');
|
|
13
|
+
const contracts = await import('./contracts');
|
|
14
|
+
|
|
15
|
+
const client = createClient({
|
|
16
|
+
endpoint: 'https://acme.uidu.org/graphql',
|
|
17
|
+
apiKey: 'key',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
beforeEach(() => request.mockReset());
|
|
21
|
+
|
|
22
|
+
describe('writes', () => {
|
|
23
|
+
it('createContract sends its attributes, custom values included, and returns the payload', async () => {
|
|
24
|
+
const payload = { contract: { node: { id: 'c1' } }, errors: [] };
|
|
25
|
+
request.mockResolvedValue({ createContract: payload });
|
|
26
|
+
const input = {
|
|
27
|
+
attributes: {
|
|
28
|
+
workspaceId: 'w1',
|
|
29
|
+
name: 'JET HR',
|
|
30
|
+
startsOn: '2027-01-01',
|
|
31
|
+
counterpartId: 'o1',
|
|
32
|
+
fieldValues: { f1: 1.21 },
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
await expect(contracts.createContract(client, { input })).resolves.toEqual(
|
|
37
|
+
payload,
|
|
38
|
+
);
|
|
39
|
+
expect(JSON.stringify(request.mock.calls[0][0])).toContain(
|
|
40
|
+
'createContract',
|
|
41
|
+
);
|
|
42
|
+
expect(request.mock.calls[0][1]).toEqual({ input });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('activateContract signs it', async () => {
|
|
46
|
+
request.mockResolvedValue({
|
|
47
|
+
activateContract: {
|
|
48
|
+
contract: { id: 'c1', aasmState: 'active' },
|
|
49
|
+
errors: [],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const result = await contracts.activateContract(client, {
|
|
54
|
+
input: { id: 'c1' },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(result?.contract?.aasmState).toBe('active');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('discardContract goes through the trash', async () => {
|
|
61
|
+
request.mockResolvedValue({
|
|
62
|
+
discardableDiscard: { discardable: { id: 'c1' }, errors: [] },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await contracts.discardContract(client, { input: { id: 'c1' } });
|
|
66
|
+
|
|
67
|
+
expect(JSON.stringify(request.mock.calls[0][0])).toContain(
|
|
68
|
+
'discardableDiscard',
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('createContractItem adds a line in cents', async () => {
|
|
73
|
+
const payload = {
|
|
74
|
+
contractItem: { node: { id: 'i1', unitAmount: 9_050_000 } },
|
|
75
|
+
errors: [],
|
|
76
|
+
};
|
|
77
|
+
request.mockResolvedValue({ createContractItem: payload });
|
|
78
|
+
const input = {
|
|
79
|
+
attributes: { contractId: 'c1', unitAmount: 9_050_000, quantity: 1 },
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
await expect(
|
|
83
|
+
contracts.createContractItem(client, { input }),
|
|
84
|
+
).resolves.toEqual(payload);
|
|
85
|
+
expect(request.mock.calls[0][1]).toEqual({ input });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('returns null when the mutation has no payload', async () => {
|
|
89
|
+
request.mockResolvedValue({ updateContract: null });
|
|
90
|
+
|
|
91
|
+
await expect(
|
|
92
|
+
contracts.updateContract(client, {
|
|
93
|
+
input: { id: 'c1', attributes: { name: 'x' } },
|
|
94
|
+
}),
|
|
95
|
+
).resolves.toBeNull();
|
|
96
|
+
});
|
|
97
|
+
});
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
ActivateContractDocument,
|
|
4
|
+
type ActivateContractMutationVariables,
|
|
5
|
+
CreateContractDocument,
|
|
6
|
+
CreateContractItemDocument,
|
|
7
|
+
type CreateContractItemMutationVariables,
|
|
8
|
+
type CreateContractMutationVariables,
|
|
9
|
+
DeleteContractItemDocument,
|
|
10
|
+
type DeleteContractItemMutationVariables,
|
|
11
|
+
DiscardContractDocument,
|
|
12
|
+
type DiscardContractMutationVariables,
|
|
13
|
+
UpdateContractDocument,
|
|
14
|
+
UpdateContractItemDocument,
|
|
15
|
+
type UpdateContractItemMutationVariables,
|
|
16
|
+
type UpdateContractMutationVariables,
|
|
17
|
+
GetContractDocument,
|
|
18
|
+
type GetContractQuery,
|
|
19
|
+
type GetContractQueryVariables,
|
|
20
|
+
ListContractsDocument,
|
|
21
|
+
type ListContractsQuery,
|
|
22
|
+
type ListContractsQueryVariables,
|
|
23
|
+
} from './generated';
|
|
24
|
+
import { nodes } from './utils/relay';
|
|
25
|
+
|
|
26
|
+
// Contracts: an agreement with a counterpart (a Contact or an Organization),
|
|
27
|
+
// booked on an analytic account. Like deals, a contract carries the custom
|
|
28
|
+
// fields the workspace added to it: read them as `fieldValuesByShortname`
|
|
29
|
+
// (`{ shortname: value }`) or `fieldValues`, write them as `fieldValues`
|
|
30
|
+
// (`{ fieldGlobalId: value }`) on create and update. A contract is a draft
|
|
31
|
+
// until `activateContract` signs it; its money is in `contractItems`, one line
|
|
32
|
+
// each with an amount in cents and its own dates. The sector a contract
|
|
33
|
+
// belongs to is `analyticAccount.effectiveResponsibleCircle`.
|
|
34
|
+
|
|
35
|
+
export type Contract = NonNullable<
|
|
36
|
+
NonNullable<
|
|
37
|
+
NonNullable<
|
|
38
|
+
NonNullable<ListContractsQuery['currentWorkspace']>['contracts']['edges']
|
|
39
|
+
>[number]
|
|
40
|
+
>['node']
|
|
41
|
+
>;
|
|
42
|
+
export type ContractDetail = NonNullable<
|
|
43
|
+
NonNullable<GetContractQuery['currentWorkspace']>['contract']
|
|
44
|
+
>;
|
|
45
|
+
|
|
46
|
+
/** The workspace's contracts with their custom fields, filtered with `params`; page with `first`/`after`. */
|
|
47
|
+
export async function listContracts(
|
|
48
|
+
client: UiduClient,
|
|
49
|
+
variables: ListContractsQueryVariables = {},
|
|
50
|
+
): Promise<Contract[]> {
|
|
51
|
+
const result = await client.query(ListContractsDocument, variables);
|
|
52
|
+
return nodes(result.currentWorkspace?.contracts);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One contract with its field values and the fields that apply to it, or null. */
|
|
56
|
+
export async function getContract(
|
|
57
|
+
client: UiduClient,
|
|
58
|
+
variables: GetContractQueryVariables,
|
|
59
|
+
): Promise<ContractDetail | null> {
|
|
60
|
+
const result = await client.query(GetContractDocument, variables);
|
|
61
|
+
return result.currentWorkspace?.contract ?? null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create a contract: `{ input: { attributes: { workspaceId, name, startsOn,
|
|
66
|
+
* endsOn, counterpartId, analyticAccountId, fieldValues } } }`. `counterpartId`
|
|
67
|
+
* is an Organization or Contact (see `createOrganization` for a new client).
|
|
68
|
+
* The new contract starts as a draft. Returns the payload (with `errors`) or
|
|
69
|
+
* null; the contract is at `contract.node`.
|
|
70
|
+
*/
|
|
71
|
+
export async function createContract(
|
|
72
|
+
client: UiduClient,
|
|
73
|
+
variables: CreateContractMutationVariables,
|
|
74
|
+
) {
|
|
75
|
+
const result = await client.mutate(CreateContractDocument, variables);
|
|
76
|
+
return result.createContract ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Update a contract's terms, client, analytic account or custom `fieldValues`:
|
|
81
|
+
* `{ input: { id, attributes } }`. Returns the payload (with `errors`) or null.
|
|
82
|
+
*/
|
|
83
|
+
export async function updateContract(
|
|
84
|
+
client: UiduClient,
|
|
85
|
+
variables: UpdateContractMutationVariables,
|
|
86
|
+
) {
|
|
87
|
+
const result = await client.mutate(UpdateContractDocument, variables);
|
|
88
|
+
return result.updateContract ?? null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Sign a draft contract (draft → active): `{ input: { id } }`. Returns the payload or null. */
|
|
92
|
+
export async function activateContract(
|
|
93
|
+
client: UiduClient,
|
|
94
|
+
variables: ActivateContractMutationVariables,
|
|
95
|
+
) {
|
|
96
|
+
const result = await client.mutate(ActivateContractDocument, variables);
|
|
97
|
+
return result.activateContract ?? null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Move a contract to the trash (restorable for 30 days): `{ input: { id } }`. Returns the payload or null. */
|
|
101
|
+
export async function discardContract(
|
|
102
|
+
client: UiduClient,
|
|
103
|
+
variables: DiscardContractMutationVariables,
|
|
104
|
+
) {
|
|
105
|
+
const result = await client.mutate(DiscardContractDocument, variables);
|
|
106
|
+
return result.discardableDiscard ?? null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Add an economic line to a contract: `{ input: { attributes: { contractId,
|
|
111
|
+
* description, quantity, unitAmount, startsAt, endsAt } } }`, with
|
|
112
|
+
* `unitAmount` in cents. Returns the payload (with `errors`) or null; the line
|
|
113
|
+
* is at `contractItem.node`.
|
|
114
|
+
*/
|
|
115
|
+
export async function createContractItem(
|
|
116
|
+
client: UiduClient,
|
|
117
|
+
variables: CreateContractItemMutationVariables,
|
|
118
|
+
) {
|
|
119
|
+
const result = await client.mutate(CreateContractItemDocument, variables);
|
|
120
|
+
return result.createContractItem ?? null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Update a contract line: `{ input: { id, attributes } }`. Returns the payload (with `errors`) or null. */
|
|
124
|
+
export async function updateContractItem(
|
|
125
|
+
client: UiduClient,
|
|
126
|
+
variables: UpdateContractItemMutationVariables,
|
|
127
|
+
) {
|
|
128
|
+
const result = await client.mutate(UpdateContractItemDocument, variables);
|
|
129
|
+
return result.updateContractItem ?? null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Remove a contract line: `{ input: { id } }`. Returns the payload or null. */
|
|
133
|
+
export async function deleteContractItem(
|
|
134
|
+
client: UiduClient,
|
|
135
|
+
variables: DeleteContractItemMutationVariables,
|
|
136
|
+
) {
|
|
137
|
+
const result = await client.mutate(DeleteContractItemDocument, variables);
|
|
138
|
+
return result.deleteContractItem ?? null;
|
|
139
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
GetRecordFieldValuesDocument,
|
|
4
|
+
type GetRecordFieldValuesQueryVariables,
|
|
5
|
+
ListFieldValueHistoryDocument,
|
|
6
|
+
type ListFieldValueHistoryQueryVariables,
|
|
7
|
+
type RecordFieldValueFragment,
|
|
8
|
+
} from './generated';
|
|
9
|
+
import { paginate } from './utils/paginate';
|
|
10
|
+
|
|
11
|
+
// Field values over time. A value holds from `validFrom` (a row without one
|
|
12
|
+
// counts from the day of its `createdAt`); a field's history on a record is
|
|
13
|
+
// every value it has held, oldest first. Reads need an account (Bearer).
|
|
14
|
+
|
|
15
|
+
export type RecordFieldValue = RecordFieldValueFragment;
|
|
16
|
+
|
|
17
|
+
export type RecordFieldValues = {
|
|
18
|
+
/** The record's GraphQL type, e.g. `Contact`, `Contract`, `Employee`. */
|
|
19
|
+
typename: string;
|
|
20
|
+
id: string;
|
|
21
|
+
/** Current values keyed by field shortname. */
|
|
22
|
+
byShortname: Record<string, unknown>;
|
|
23
|
+
/** Current values with their field and dates. */
|
|
24
|
+
fieldValues: RecordFieldValue[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The current field values of any record that carries custom fields (contact,
|
|
29
|
+
* employee, contract, work site, application…), by GlobalID; null when the id
|
|
30
|
+
* resolves to nothing or to a type without fields.
|
|
31
|
+
*/
|
|
32
|
+
export async function getRecordFieldValues(
|
|
33
|
+
client: UiduClient,
|
|
34
|
+
variables: GetRecordFieldValuesQueryVariables,
|
|
35
|
+
): Promise<RecordFieldValues | null> {
|
|
36
|
+
const result = await client.query(GetRecordFieldValuesDocument, variables);
|
|
37
|
+
const node = result.node;
|
|
38
|
+
if (!node || !('fieldValues' in node)) return null;
|
|
39
|
+
return {
|
|
40
|
+
typename: node.__typename,
|
|
41
|
+
id: node.id,
|
|
42
|
+
byShortname: (node.fieldValuesByShortname ?? {}) as Record<string, unknown>,
|
|
43
|
+
fieldValues: node.fieldValues ?? [],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Every value `fieldId` has held on the record `modelId`, oldest first, walking
|
|
49
|
+
* all pages. Pair it with {@link fieldValueAsOf} to answer "what did it say on
|
|
50
|
+
* a given day?".
|
|
51
|
+
*/
|
|
52
|
+
export async function listFieldValueHistory(
|
|
53
|
+
client: UiduClient,
|
|
54
|
+
variables: Omit<ListFieldValueHistoryQueryVariables, 'after'>,
|
|
55
|
+
): Promise<RecordFieldValue[]> {
|
|
56
|
+
return paginate(client, ListFieldValueHistoryDocument, {
|
|
57
|
+
variables: { first: 100, ...variables },
|
|
58
|
+
extract: (data) => data.currentWorkspace?.field?.fieldValues,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The day a value starts to hold: `validFrom`, else the day of `createdAt`. */
|
|
63
|
+
function holdsFrom(value: RecordFieldValue): string {
|
|
64
|
+
return String(value.validFrom ?? String(value.createdAt).slice(0, 10));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The value that held on `date` (an ISO8601 date, default today) among a
|
|
69
|
+
* field's history: the latest `validFrom` not after the date, ties going to
|
|
70
|
+
* the row written last. Null when nothing held yet.
|
|
71
|
+
*
|
|
72
|
+
* The same rule uidu applies server-side for a record's current value; the
|
|
73
|
+
* GraphQL API takes no as-of argument, so reports read the history with
|
|
74
|
+
* {@link listFieldValueHistory} and pick here.
|
|
75
|
+
*/
|
|
76
|
+
export function fieldValueAsOf(
|
|
77
|
+
history: readonly RecordFieldValue[],
|
|
78
|
+
date: string = new Date().toISOString().slice(0, 10),
|
|
79
|
+
): RecordFieldValue | null {
|
|
80
|
+
const day = date.slice(0, 10);
|
|
81
|
+
let best: RecordFieldValue | null = null;
|
|
82
|
+
for (const value of history) {
|
|
83
|
+
const from = holdsFrom(value);
|
|
84
|
+
if (from > day) continue;
|
|
85
|
+
if (
|
|
86
|
+
!best ||
|
|
87
|
+
from > holdsFrom(best) ||
|
|
88
|
+
(from === holdsFrom(best) &&
|
|
89
|
+
String(value.createdAt) >= String(best.createdAt))
|
|
90
|
+
) {
|
|
91
|
+
best = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return best;
|
|
95
|
+
}
|