@uidu/client 3.4.0 → 3.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uidu/client",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Typed GraphQL client for the uidu platform. Server-first, framework-agnostic.",
5
5
  "license": "MIT",
6
6
  "author": "uidu",
@@ -0,0 +1,165 @@
1
+ import { afterEach, 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 { createFormResponse } = await import('./forms');
14
+ const { CreateFormResponseDocument, CreatePageDocument, GetFormDocument } =
15
+ await import('./generated');
16
+
17
+ const client = createClient({ workspace: 'acme', apiKey: 'k' });
18
+
19
+ beforeEach(() => {
20
+ request.mockResolvedValue({});
21
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
22
+ });
23
+
24
+ afterEach(() => {
25
+ vi.restoreAllMocks();
26
+ request.mockReset();
27
+ });
28
+
29
+ const sentVariables = () => request.mock.calls[0][1];
30
+
31
+ describe('UiduClient.mutate — fieldValuesAttributes normalization', () => {
32
+ it('wraps a flat `content` on a form response', async () => {
33
+ await createFormResponse(client, {
34
+ input: {
35
+ event: 'complete!',
36
+ attributes: {
37
+ formId: 'form_1',
38
+ fieldValuesAttributes: [
39
+ { fieldId: 'f1', content: 'hello' },
40
+ { fieldId: 'f2', content: { value: 'already wrapped' } },
41
+ ],
42
+ },
43
+ },
44
+ });
45
+
46
+ expect(sentVariables().input.attributes.fieldValuesAttributes).toEqual([
47
+ { fieldId: 'f1', content: { value: 'hello' } },
48
+ { fieldId: 'f2', content: { value: 'already wrapped' } },
49
+ ]);
50
+ });
51
+
52
+ it('reaches nested attributes (contactAttributes.contactableAttributes)', async () => {
53
+ await client.mutate(CreateFormResponseDocument, {
54
+ input: {
55
+ attributes: {
56
+ formId: 'form_1',
57
+ contactAttributes: {
58
+ email: 'a@b.c',
59
+ contactableAttributes: {
60
+ kind: 'person',
61
+ fieldValuesAttributes: [{ fieldId: 'f9', content: 'nested' }],
62
+ },
63
+ },
64
+ },
65
+ },
66
+ } as never);
67
+
68
+ expect(
69
+ sentVariables().input.attributes.contactAttributes.contactableAttributes
70
+ .fieldValuesAttributes,
71
+ ).toEqual([{ fieldId: 'f9', content: { value: 'nested' } }]);
72
+ });
73
+
74
+ it('reaches through arrays (pageBlocksAttributes[])', async () => {
75
+ await client.mutate(CreatePageDocument, {
76
+ input: {
77
+ attributes: {
78
+ name: 'Home',
79
+ pageBlocksAttributes: [
80
+ { fieldValuesAttributes: [{ fieldId: 'f1', content: 'a' }] },
81
+ {
82
+ fieldValuesAttributes: [
83
+ { fieldId: 'f2', content: { value: 'b' } },
84
+ ],
85
+ },
86
+ ],
87
+ },
88
+ },
89
+ } as never);
90
+
91
+ expect(sentVariables().input.attributes.pageBlocksAttributes).toEqual([
92
+ { fieldValuesAttributes: [{ fieldId: 'f1', content: { value: 'a' } }] },
93
+ { fieldValuesAttributes: [{ fieldId: 'f2', content: { value: 'b' } }] },
94
+ ]);
95
+ });
96
+
97
+ it('does not descend into the `content` payload itself', async () => {
98
+ const doc = {
99
+ type: 'doc',
100
+ // a rich text document that happens to carry the magic key
101
+ fieldValuesAttributes: [{ fieldId: 'nope', content: 'leave me' }],
102
+ };
103
+
104
+ await client.mutate(CreateFormResponseDocument, {
105
+ input: {
106
+ attributes: {
107
+ fieldValuesAttributes: [{ fieldId: 'f1', content: { value: doc } }],
108
+ },
109
+ },
110
+ } as never);
111
+
112
+ expect(
113
+ sentVariables().input.attributes.fieldValuesAttributes[0].content.value,
114
+ ).toEqual(doc);
115
+ });
116
+
117
+ it('leaves mutations without field values untouched, by reference', async () => {
118
+ const variables = {
119
+ input: { attributes: { name: 'Home', slug: 'home' } },
120
+ };
121
+ await client.mutate(CreatePageDocument, variables as never);
122
+
123
+ expect(sentVariables()).toBe(variables);
124
+ });
125
+
126
+ it('does not mutate the caller’s object', async () => {
127
+ const variables = {
128
+ input: {
129
+ attributes: {
130
+ fieldValuesAttributes: [{ fieldId: 'f1', content: 'flat' }],
131
+ },
132
+ },
133
+ };
134
+ await client.mutate(CreateFormResponseDocument, variables as never);
135
+
136
+ expect(variables.input.attributes.fieldValuesAttributes[0].content).toBe(
137
+ 'flat',
138
+ );
139
+ });
140
+
141
+ it('warns once per mutation, not once per entry', async () => {
142
+ await client.mutate(CreateFormResponseDocument, {
143
+ input: {
144
+ attributes: {
145
+ fieldValuesAttributes: [
146
+ { fieldId: 'f1', content: 'a' },
147
+ { fieldId: 'f2', content: 'b' },
148
+ { fieldId: 'f3', content: 'c' },
149
+ ],
150
+ },
151
+ },
152
+ } as never);
153
+
154
+ expect(console.warn).toHaveBeenCalledTimes(1);
155
+ });
156
+ });
157
+
158
+ describe('UiduClient.query', () => {
159
+ it('does not normalize — reads have no field value payloads', async () => {
160
+ const variables = { id: 'form_1' };
161
+ await client.query(GetFormDocument, variables);
162
+
163
+ expect(sentVariables()).toBe(variables);
164
+ });
165
+ });
package/src/client.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
2
  import { ClientError, GraphQLClient } from 'graphql-request';
3
3
  import { UiduError, type UiduClientConfig } from './types';
4
+ import { normalizeMutationVariables } from './utils/fieldValues';
4
5
 
5
6
  export class UiduClient {
6
7
  readonly endpoint: string;
@@ -35,7 +36,10 @@ export class UiduClient {
35
36
  document: TypedDocumentNode<TResult, TVariables>,
36
37
  variables?: TVariables,
37
38
  ): Promise<TResult> {
38
- return this.query(document, variables);
39
+ // `fieldValuesAttributes[].content` must be `{ value: … }`; a bare value is
40
+ // accepted by the API but silently discarded. Fix it up for every mutation
41
+ // rather than at each of the ~50 call sites. See ./utils/fieldValues.
42
+ return this.query(document, normalizeMutationVariables(variables));
39
43
  }
40
44
  }
41
45
 
@@ -29960,6 +29960,8 @@ export type NoteAttributes = {
29960
29960
  relatedAttributes?: InputMaybe<Array<RelationshipAttributes>>;
29961
29961
  /** Relationships */
29962
29962
  relationshipsAttributes?: InputMaybe<Array<RelationshipAttributes>>;
29963
+ /** The app instance this note lives in */
29964
+ workspaceAppId?: InputMaybe<Scalars['ID']['input']>;
29963
29965
  };
29964
29966
 
29965
29967
  /** The connection type for Note. */
@@ -30058,7 +30060,7 @@ export type NoteTemplateEdge = {
30058
30060
  };
30059
30061
 
30060
30062
  /** Objects can be applied to */
30061
- export type Notifiable = Application | Blob | Comment | Contact | Donation | EventStoreEvent | Export | FormResponse | Import | Mention | Order | Task | Ticket;
30063
+ export type Notifiable = Application | Blob | Comment | Contact | Donation | EventStoreEvent | Export | FormResponse | Import | Mention | Order | Space | Task | Ticket | Workspace;
30062
30064
 
30063
30065
  export type Notification = ActiveRecordTimestamp & Node & {
30064
30066
  __typename?: 'Notification';
@@ -49366,7 +49368,7 @@ export type ListCallsQueryVariables = Exact<{
49366
49368
  }>;
49367
49369
 
49368
49370
 
49369
- export type ListCallsQuery = { __typename?: 'Query', currentWorkspace?: { __typename?: 'Workspace', calls: { __typename?: 'CallConnection', pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, endCursor?: string | null }, edges?: Array<{ __typename?: 'CallEdge', node?: { __typename?: 'Call', id: string, name?: string | null, cover?: string | null, coverData?: any | null, kind: CallKind, status?: string | null, quantity?: number | null, salaryMin?: number | null, salaryMax?: number | null, publishedAt?: any | null, expiresAt?: any | null, publicPath?: string | null, published?: boolean | null, primaryAddress?: { __typename?: 'Address', id: string, formattedAddress?: string | null, city?: string | null } | null } | null } | null> | null } } | null };
49371
+ export type ListCallsQuery = { __typename?: 'Query', currentWorkspace?: { __typename?: 'Workspace', calls: { __typename?: 'CallConnection', pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, endCursor?: string | null }, edges?: Array<{ __typename?: 'CallEdge', node?: { __typename?: 'Call', id: string, name?: string | null, cover?: string | null, coverData?: any | null, kind: CallKind, status?: string | null, quantity?: number | null, salaryMin?: number | null, salaryMax?: number | null, publishedAt?: any | null, expiresAt?: any | null, publicUrl?: string | null, publicPath?: string | null, published?: boolean | null, primaryAddress?: { __typename?: 'Address', id: string, formattedAddress?: string | null, city?: string | null } | null } | null } | null> | null } } | null };
49370
49372
 
49371
49373
  export type GetCampaignQueryVariables = Exact<{
49372
49374
  id: Scalars['ID']['input'];
@@ -50050,7 +50052,7 @@ export const ListBookingsDocument = {"kind":"Document","definitions":[{"kind":"O
50050
50052
  export const ListCalendarEventsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ListCalendarEvents"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"before"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"last"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"calendarIds"}},"type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"scopes"}},"type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"calendarEvents"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}},{"kind":"Argument","name":{"kind":"Name","value":"before"},"value":{"kind":"Variable","name":{"kind":"Name","value":"before"}}},{"kind":"Argument","name":{"kind":"Name","value":"last"},"value":{"kind":"Variable","name":{"kind":"Name","value":"last"}}},{"kind":"Argument","name":{"kind":"Name","value":"calendarIds"},"value":{"kind":"Variable","name":{"kind":"Name","value":"calendarIds"}}},{"kind":"Argument","name":{"kind":"Name","value":"scopes"},"value":{"kind":"Variable","name":{"kind":"Name","value":"scopes"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"startTime"}},{"kind":"Field","name":{"kind":"Name","value":"endTime"}},{"kind":"Field","name":{"kind":"Name","value":"allDay"}},{"kind":"Field","name":{"kind":"Name","value":"timeZone"}},{"kind":"Field","name":{"kind":"Name","value":"url"}},{"kind":"Field","name":{"kind":"Name","value":"calendar"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"color"}}]}},{"kind":"Field","name":{"kind":"Name","value":"primaryAddress"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"formattedAddress"}},{"kind":"Field","name":{"kind":"Name","value":"city"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<ListCalendarEventsQuery, ListCalendarEventsQueryVariables>;
50051
50053
  export const ListCalendarsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ListCalendars"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"before"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"last"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"calendars"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}},{"kind":"Argument","name":{"kind":"Name","value":"before"},"value":{"kind":"Variable","name":{"kind":"Name","value":"before"}}},{"kind":"Argument","name":{"kind":"Name","value":"last"},"value":{"kind":"Variable","name":{"kind":"Name","value":"last"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"color"}},{"kind":"Field","name":{"kind":"Name","value":"timeZone"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<ListCalendarsQuery, ListCalendarsQueryVariables>;
50052
50054
  export const GetCallDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCall"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"call"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"body"}},{"kind":"Field","name":{"kind":"Name","value":"cover"}},{"kind":"Field","name":{"kind":"Name","value":"coverData"}},{"kind":"Field","name":{"kind":"Name","value":"kind"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"salaryMin"}},{"kind":"Field","name":{"kind":"Name","value":"salaryMax"}},{"kind":"Field","name":{"kind":"Name","value":"publishedAt"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}},{"kind":"Field","name":{"kind":"Name","value":"completedAt"}},{"kind":"Field","name":{"kind":"Name","value":"publicUrl"}},{"kind":"Field","name":{"kind":"Name","value":"publicPath"}},{"kind":"Field","name":{"kind":"Name","value":"primaryAddress"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"formattedAddress"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"city"}},{"kind":"Field","name":{"kind":"Name","value":"countryCode"}}]}},{"kind":"Field","name":{"kind":"Name","value":"form"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FormFields"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FormFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Form"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"inputs"},"name":{"kind":"Name","value":"formQuestions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"required"}},{"kind":"Field","name":{"kind":"Name","value":"hidden"}},{"kind":"Field","name":{"kind":"Name","value":"placeholder"}},{"kind":"Field","name":{"kind":"Name","value":"hint"}},{"kind":"Field","name":{"kind":"Name","value":"fieldKind"}},{"kind":"Field","name":{"kind":"Name","value":"rules"}},{"kind":"Field","name":{"kind":"Name","value":"preferences"}},{"kind":"Field","name":{"kind":"Name","value":"field"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"kind"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"accessor"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"shortname"}},{"kind":"Field","name":{"kind":"Name","value":"uploadPresignedUrl"}},{"kind":"Field","name":{"kind":"Name","value":"uploadUrl"}},{"kind":"Field","name":{"kind":"Name","value":"uploadParams"}},{"kind":"Field","alias":{"kind":"Name","value":"options"},"name":{"kind":"Name","value":"optionList"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetCallQuery, GetCallQueryVariables>;
50053
- export const ListCallsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ListCalls"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"calls"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"cover"}},{"kind":"Field","name":{"kind":"Name","value":"coverData"}},{"kind":"Field","name":{"kind":"Name","value":"kind"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"salaryMin"}},{"kind":"Field","name":{"kind":"Name","value":"salaryMax"}},{"kind":"Field","name":{"kind":"Name","value":"publishedAt"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}},{"kind":"Field","name":{"kind":"Name","value":"publicPath"}},{"kind":"Field","name":{"kind":"Name","value":"published"}},{"kind":"Field","name":{"kind":"Name","value":"primaryAddress"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"formattedAddress"}},{"kind":"Field","name":{"kind":"Name","value":"city"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<ListCallsQuery, ListCallsQueryVariables>;
50055
+ export const ListCallsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ListCalls"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"calls"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"cover"}},{"kind":"Field","name":{"kind":"Name","value":"coverData"}},{"kind":"Field","name":{"kind":"Name","value":"kind"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"salaryMin"}},{"kind":"Field","name":{"kind":"Name","value":"salaryMax"}},{"kind":"Field","name":{"kind":"Name","value":"publishedAt"}},{"kind":"Field","name":{"kind":"Name","value":"expiresAt"}},{"kind":"Field","name":{"kind":"Name","value":"publicUrl"}},{"kind":"Field","name":{"kind":"Name","value":"publicPath"}},{"kind":"Field","name":{"kind":"Name","value":"published"}},{"kind":"Field","name":{"kind":"Name","value":"primaryAddress"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"formattedAddress"}},{"kind":"Field","name":{"kind":"Name","value":"city"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<ListCallsQuery, ListCallsQueryVariables>;
50054
50056
  export const GetCampaignDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCampaign"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"campaign"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"innerName"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"scheduledAt"}},{"kind":"Field","name":{"kind":"Name","value":"sentAt"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"preferences"}},{"kind":"Field","name":{"kind":"Name","value":"list"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetCampaignQuery, GetCampaignQueryVariables>;
50055
50057
  export const ListCampaignsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ListCampaigns"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"kind"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"status"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"campaigns"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}},{"kind":"Argument","name":{"kind":"Name","value":"kind"},"value":{"kind":"Variable","name":{"kind":"Name","value":"kind"}}},{"kind":"Argument","name":{"kind":"Name","value":"status"},"value":{"kind":"Variable","name":{"kind":"Name","value":"status"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"innerName"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"scheduledAt"}},{"kind":"Field","name":{"kind":"Name","value":"sentAt"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<ListCampaignsQuery, ListCampaignsQueryVariables>;
50056
50058
  export const ListEmailCampaignsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ListEmailCampaigns"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"status"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"emailCampaigns"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}},{"kind":"Argument","name":{"kind":"Name","value":"status"},"value":{"kind":"Variable","name":{"kind":"Name","value":"status"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}},{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"subject"}},{"kind":"Field","name":{"kind":"Name","value":"replyTo"}},{"kind":"Field","name":{"kind":"Name","value":"sentCount"}},{"kind":"Field","name":{"kind":"Name","value":"deliveredCount"}},{"kind":"Field","name":{"kind":"Name","value":"openedCount"}},{"kind":"Field","name":{"kind":"Name","value":"clickedCount"}},{"kind":"Field","name":{"kind":"Name","value":"openRate"}},{"kind":"Field","name":{"kind":"Name","value":"clickRate"}},{"kind":"Field","name":{"kind":"Name","value":"uniqueOpens"}},{"kind":"Field","name":{"kind":"Name","value":"uniqueClicks"}},{"kind":"Field","name":{"kind":"Name","value":"lastOpenedAt"}},{"kind":"Field","name":{"kind":"Name","value":"lastClickedAt"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"campaign"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"status"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<ListEmailCampaignsQuery, ListEmailCampaignsQueryVariables>;
package/src/index.ts CHANGED
@@ -5,6 +5,11 @@ export type { UiduClientConfig, UiduErrorOptions } from './types';
5
5
  export { paginate } from './utils/paginate';
6
6
  export type { PaginateOptions } from './utils/paginate';
7
7
 
8
+ export {
9
+ normalizeFieldValueContent,
10
+ normalizeFieldValuesAttributes,
11
+ } from './utils/fieldValues';
12
+
8
13
  export {
9
14
  ListApplicationsDocument,
10
15
  ListBookingsDocument,
@@ -38,10 +43,7 @@ export {
38
43
  } from './cms';
39
44
  export type { Page, Template } from './cms';
40
45
 
41
- export {
42
- createWorkspace,
43
- generateWorkspaceApiCredentials,
44
- } from './system';
46
+ export { createWorkspace, generateWorkspaceApiCredentials } from './system';
45
47
 
46
48
  export { createSpace } from './spaces';
47
49
  export { createTask } from './tasks';
@@ -169,19 +171,10 @@ export {
169
171
  } from './courses';
170
172
  export type { Course, Enrollment, Lecture } from './courses';
171
173
 
172
- export {
173
- getCampaign,
174
- listCampaigns,
175
- listEmailCampaigns,
176
- } from './campaigns';
174
+ export { getCampaign, listCampaigns, listEmailCampaigns } from './campaigns';
177
175
  export type { Campaign } from './campaigns';
178
176
 
179
- export {
180
- getContact,
181
- listContacts,
182
- getDeal,
183
- listDeals,
184
- } from './contacts';
177
+ export { getContact, listContacts, getDeal, listDeals } from './contacts';
185
178
  export type { Contact, Deal } from './contacts';
186
179
 
187
180
  export {
@@ -18,6 +18,7 @@ query ListCalls($first: Int, $after: String) {
18
18
  salaryMax
19
19
  publishedAt
20
20
  expiresAt
21
+ publicUrl
21
22
  publicPath
22
23
  published
23
24
  primaryAddress {
@@ -0,0 +1,268 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import {
3
+ normalizeFieldValueContent,
4
+ normalizeFieldValuesAttributes,
5
+ normalizeMutationVariables,
6
+ } from './fieldValues';
7
+
8
+ afterEach(() => {
9
+ vi.restoreAllMocks();
10
+ });
11
+
12
+ describe('normalizeFieldValueContent', () => {
13
+ it('leaves null and undefined alone', () => {
14
+ expect(normalizeFieldValueContent(null)).toBeNull();
15
+ expect(normalizeFieldValueContent(undefined)).toBeUndefined();
16
+ });
17
+
18
+ it('leaves an already-wrapped payload alone', () => {
19
+ const content = { value: 'hello' };
20
+ expect(normalizeFieldValueContent(content)).toBe(content);
21
+ });
22
+
23
+ it('leaves an explicit null value alone', () => {
24
+ const content = { value: null };
25
+ expect(normalizeFieldValueContent(content)).toBe(content);
26
+ });
27
+
28
+ it('wraps a bare string', () => {
29
+ expect(normalizeFieldValueContent('hello')).toEqual({ value: 'hello' });
30
+ });
31
+
32
+ it('wraps a bare number, boolean and zero', () => {
33
+ expect(normalizeFieldValueContent(42)).toEqual({ value: 42 });
34
+ expect(normalizeFieldValueContent(false)).toEqual({ value: false });
35
+ expect(normalizeFieldValueContent(0)).toEqual({ value: 0 });
36
+ });
37
+
38
+ it('wraps an array (multipleSelect answers)', () => {
39
+ expect(normalizeFieldValueContent(['a', 'b'])).toEqual({
40
+ value: ['a', 'b'],
41
+ });
42
+ });
43
+
44
+ it('wraps an object that has no value key (richText / json answers)', () => {
45
+ const doc = { type: 'doc', content: [] };
46
+ expect(normalizeFieldValueContent(doc)).toEqual({ value: doc });
47
+ });
48
+ });
49
+
50
+ describe('normalizeFieldValuesAttributes', () => {
51
+ it('passes null / undefined through', () => {
52
+ expect(normalizeFieldValuesAttributes(null)).toBeNull();
53
+ expect(normalizeFieldValuesAttributes(undefined)).toBeUndefined();
54
+ });
55
+
56
+ it('returns the same array reference when nothing needs wrapping', () => {
57
+ const attributes = [{ fieldId: '1', content: { value: 'a' } }];
58
+ expect(normalizeFieldValuesAttributes(attributes)).toBe(attributes);
59
+ });
60
+
61
+ it('wraps only the entries that need it, keeping order', () => {
62
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
63
+ const attributes = [
64
+ { fieldId: '1', content: 'flat' },
65
+ { fieldId: '2', content: { value: 'wrapped' } },
66
+ { fieldId: '3', content: 3 },
67
+ ];
68
+
69
+ expect(normalizeFieldValuesAttributes(attributes)).toEqual([
70
+ { fieldId: '1', content: { value: 'flat' } },
71
+ { fieldId: '2', content: { value: 'wrapped' } },
72
+ { fieldId: '3', content: { value: 3 } },
73
+ ]);
74
+ expect(warn).toHaveBeenCalledTimes(1);
75
+ });
76
+
77
+ it('preserves sibling attributes such as id and linkedRecordId', () => {
78
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
79
+ expect(
80
+ normalizeFieldValuesAttributes([
81
+ { fieldId: '1', id: 'fv_1', linkedRecordId: 'lr_1', content: 'x' },
82
+ ]),
83
+ ).toEqual([
84
+ {
85
+ fieldId: '1',
86
+ id: 'fv_1',
87
+ linkedRecordId: 'lr_1',
88
+ content: { value: 'x' },
89
+ },
90
+ ]);
91
+ });
92
+
93
+ it('leaves entries without a content key alone', () => {
94
+ const attributes = [{ fieldId: '1', linkedRecordId: 'lr_1' }];
95
+ expect(normalizeFieldValuesAttributes(attributes)).toBe(attributes);
96
+ });
97
+
98
+ it('does not warn in production', () => {
99
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
100
+ vi.stubEnv('NODE_ENV', 'production');
101
+
102
+ normalizeFieldValuesAttributes([{ fieldId: '1', content: 'flat' }]);
103
+ expect(warn).not.toHaveBeenCalled();
104
+
105
+ vi.unstubAllEnvs();
106
+ });
107
+ });
108
+
109
+ describe('normalizeMutationVariables', () => {
110
+ it('passes non-objects through', () => {
111
+ expect(normalizeMutationVariables(undefined)).toBeUndefined();
112
+ expect(normalizeMutationVariables('x')).toBe('x');
113
+ });
114
+
115
+ it('returns the same object when there is nothing to normalize', () => {
116
+ const variables = {
117
+ input: {
118
+ attributes: {
119
+ formId: 'form_1',
120
+ fieldValuesAttributes: [{ fieldId: '1', content: { value: 'a' } }],
121
+ },
122
+ },
123
+ };
124
+ expect(normalizeMutationVariables(variables)).toBe(variables);
125
+ });
126
+
127
+ it('returns the same object when there are no fieldValuesAttributes', () => {
128
+ const variables = { input: { attributes: { formId: 'form_1' } } };
129
+ expect(normalizeMutationVariables(variables)).toBe(variables);
130
+ });
131
+
132
+ it('rewrites flat content without mutating the caller input', () => {
133
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
134
+ const variables = {
135
+ input: {
136
+ event: 'complete!',
137
+ attributes: {
138
+ formId: 'form_1',
139
+ contactAttributes: { email: 'a@b.c' },
140
+ fieldValuesAttributes: [{ fieldId: '1', content: 'flat' }],
141
+ },
142
+ },
143
+ };
144
+
145
+ expect(normalizeMutationVariables(variables)).toEqual({
146
+ input: {
147
+ event: 'complete!',
148
+ attributes: {
149
+ formId: 'form_1',
150
+ contactAttributes: { email: 'a@b.c' },
151
+ fieldValuesAttributes: [{ fieldId: '1', content: { value: 'flat' } }],
152
+ },
153
+ },
154
+ });
155
+ expect(variables.input.attributes.fieldValuesAttributes[0].content).toBe(
156
+ 'flat',
157
+ );
158
+ });
159
+
160
+ it('finds fieldValuesAttributes nested behind other attributes', () => {
161
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
162
+ const result = normalizeMutationVariables({
163
+ input: {
164
+ attributes: {
165
+ contactAttributes: {
166
+ contactableAttributes: {
167
+ fieldValuesAttributes: [{ fieldId: '1', content: 'deep' }],
168
+ },
169
+ },
170
+ },
171
+ },
172
+ });
173
+
174
+ expect(
175
+ result.input.attributes.contactAttributes.contactableAttributes
176
+ .fieldValuesAttributes,
177
+ ).toEqual([{ fieldId: '1', content: { value: 'deep' } }]);
178
+ });
179
+
180
+ it('finds fieldValuesAttributes inside arrays of attributes', () => {
181
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
182
+ const result = normalizeMutationVariables({
183
+ input: {
184
+ attributes: {
185
+ pageBlocksAttributes: [
186
+ { fieldValuesAttributes: [{ fieldId: '1', content: 'a' }] },
187
+ ],
188
+ },
189
+ },
190
+ });
191
+
192
+ expect(
193
+ result.input.attributes.pageBlocksAttributes[0].fieldValuesAttributes,
194
+ ).toEqual([{ fieldId: '1', content: { value: 'a' } }]);
195
+ });
196
+
197
+ it('shares references for untouched subtrees', () => {
198
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
199
+ const contactAttributes = { email: 'a@b.c' };
200
+ const result = normalizeMutationVariables({
201
+ input: {
202
+ attributes: {
203
+ contactAttributes,
204
+ fieldValuesAttributes: [{ fieldId: '1', content: 'flat' }],
205
+ },
206
+ },
207
+ });
208
+
209
+ expect(result.input.attributes.contactAttributes).toBe(contactAttributes);
210
+ });
211
+
212
+ it('does not descend into a content payload that carries the magic key', () => {
213
+ const doc = {
214
+ fieldValuesAttributes: [{ fieldId: 'nope', content: 'leave me' }],
215
+ };
216
+ const result = normalizeMutationVariables({
217
+ input: {
218
+ attributes: {
219
+ fieldValuesAttributes: [{ fieldId: '1', content: { value: doc } }],
220
+ },
221
+ },
222
+ });
223
+
224
+ expect(result.input.attributes.fieldValuesAttributes[0].content.value).toBe(
225
+ doc,
226
+ );
227
+ });
228
+
229
+ it('normalizes nested field values on a field value entry', () => {
230
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
231
+ const result = normalizeMutationVariables({
232
+ input: {
233
+ attributes: {
234
+ fieldValuesAttributes: [
235
+ {
236
+ fieldId: '1',
237
+ content: { value: 'parent' },
238
+ fieldValuesAttributes: [{ fieldId: '2', content: 'child' }],
239
+ },
240
+ ],
241
+ },
242
+ },
243
+ });
244
+
245
+ expect(
246
+ result.input.attributes.fieldValuesAttributes[0].fieldValuesAttributes,
247
+ ).toEqual([{ fieldId: '2', content: { value: 'child' } }]);
248
+ });
249
+
250
+ it('warns once for a whole mutation, however many entries were wrapped', () => {
251
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
252
+ normalizeMutationVariables({
253
+ input: {
254
+ attributes: {
255
+ fieldValuesAttributes: [
256
+ { fieldId: '1', content: 'a' },
257
+ { fieldId: '2', content: 'b' },
258
+ ],
259
+ pageBlocksAttributes: [
260
+ { fieldValuesAttributes: [{ fieldId: '3', content: 'c' }] },
261
+ ],
262
+ },
263
+ },
264
+ });
265
+
266
+ expect(warn).toHaveBeenCalledTimes(1);
267
+ });
268
+ });