@uidu/client 3.10.0 → 3.12.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 +12 -0
- package/dist/declarations/src/generated/index.d.ts +4798 -7
- package/dist/declarations/src/goals.d.ts +127 -0
- package/dist/declarations/src/index.d.ts +5 -1
- package/dist/declarations/src/sites.d.ts +81 -0
- package/dist/uidu-client.cjs.dev.js +218 -1
- package/dist/uidu-client.cjs.prod.js +218 -1
- package/dist/uidu-client.esm.js +203 -2
- package/package.json +1 -1
- package/src/generated/index.ts +621 -11
- package/src/goals.test.ts +90 -0
- package/src/goals.ts +144 -0
- package/src/index.ts +31 -0
- package/src/queries/goals/GetGoal.graphql +14 -0
- package/src/queries/goals/GoalFields.graphql +28 -0
- package/src/queries/goals/GoalMutations.graphql +12 -0
- package/src/queries/goals/ListGoals.graphql +15 -0
- package/src/queries/goals/ListTimeframes.graphql +20 -0
- package/src/queries/sites/SiteFields.graphql +51 -0
- package/src/queries/sites/SiteQueries.graphql +53 -0
- package/src/sites.test.ts +315 -0
- package/src/sites.ts +173 -0
|
@@ -0,0 +1,315 @@
|
|
|
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 sites = await import('./sites');
|
|
14
|
+
|
|
15
|
+
const client = createClient({ workspace: 'acme', publicToken: 'pub' });
|
|
16
|
+
|
|
17
|
+
const operation = (call: unknown[]) =>
|
|
18
|
+
(call[0] as { definitions: Array<{ name?: { value: string } }> })
|
|
19
|
+
.definitions[0].name?.value;
|
|
20
|
+
|
|
21
|
+
const site = {
|
|
22
|
+
id: 'site_1',
|
|
23
|
+
name: 'Acme',
|
|
24
|
+
shortname: 'acme',
|
|
25
|
+
domain: 'www.acme.org',
|
|
26
|
+
preferences: null,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const pageType = { id: 'mdl_page', name: 'Page', kind: 'page' };
|
|
30
|
+
const hero = { id: 'mdl_hero', name: 'Hero', kind: 'block' };
|
|
31
|
+
const faq = { id: 'mdl_faq', name: 'FAQ', kind: 'block' };
|
|
32
|
+
|
|
33
|
+
const meta = (overrides: Record<string, unknown> = {}) => ({
|
|
34
|
+
id: 'itm_home',
|
|
35
|
+
name: 'Home',
|
|
36
|
+
slug: 'home',
|
|
37
|
+
publishedAt: '2026-09-01T00:00:00Z',
|
|
38
|
+
publishableStatus: 'Published',
|
|
39
|
+
model: pageType,
|
|
40
|
+
...overrides,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const placement = (
|
|
44
|
+
position: number,
|
|
45
|
+
model: typeof hero,
|
|
46
|
+
fieldValuesByShortname: Record<string, unknown>,
|
|
47
|
+
) => ({
|
|
48
|
+
id: `plc_${position}`,
|
|
49
|
+
position,
|
|
50
|
+
fieldValueId: `fv_${position}`,
|
|
51
|
+
modelItem: {
|
|
52
|
+
id: `itm_block_${position}`,
|
|
53
|
+
name: model.name,
|
|
54
|
+
model,
|
|
55
|
+
fieldValuesByShortname,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
beforeEach(() => request.mockReset());
|
|
60
|
+
|
|
61
|
+
describe('getSiteByDomain', () => {
|
|
62
|
+
it('reads siteByDomain with the public token', async () => {
|
|
63
|
+
request.mockResolvedValue({ siteByDomain: site });
|
|
64
|
+
await expect(
|
|
65
|
+
sites.getSiteByDomain(client, { domain: 'www.acme.org' }),
|
|
66
|
+
).resolves.toEqual(site);
|
|
67
|
+
expect(operation(request.mock.calls[0])).toBe('GetSiteByDomain');
|
|
68
|
+
expect(request.mock.calls[0][1]).toEqual({ domain: 'www.acme.org' });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('returns null for an unknown domain', async () => {
|
|
72
|
+
request.mockResolvedValue({ siteByDomain: null });
|
|
73
|
+
await expect(
|
|
74
|
+
sites.getSiteByDomain(client, { domain: 'nope.org' }),
|
|
75
|
+
).resolves.toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('getSite', () => {
|
|
80
|
+
it('reads the Site through node(id:)', async () => {
|
|
81
|
+
request.mockResolvedValue({ node: { __typename: 'Site', ...site } });
|
|
82
|
+
await expect(sites.getSite(client, { id: 'site_1' })).resolves.toEqual({
|
|
83
|
+
__typename: 'Site',
|
|
84
|
+
...site,
|
|
85
|
+
});
|
|
86
|
+
expect(operation(request.mock.calls[0])).toBe('GetSite');
|
|
87
|
+
expect(request.mock.calls[0][1]).toEqual({ id: 'site_1' });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns null when the node is not a Site', async () => {
|
|
91
|
+
request.mockResolvedValue({ node: { __typename: 'Page' } });
|
|
92
|
+
await expect(sites.getSite(client, { id: 'x' })).resolves.toBeNull();
|
|
93
|
+
request.mockResolvedValue({ node: null });
|
|
94
|
+
await expect(sites.getSite(client, { id: 'x' })).resolves.toBeNull();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('getPageBySlug', () => {
|
|
99
|
+
it('maps the page, its fields and its blocks in position order', async () => {
|
|
100
|
+
request.mockResolvedValue({
|
|
101
|
+
node: {
|
|
102
|
+
__typename: 'Site',
|
|
103
|
+
id: 'site_1',
|
|
104
|
+
pageBySlug: {
|
|
105
|
+
...meta(),
|
|
106
|
+
fieldValuesByShortname: { title: 'Welcome' },
|
|
107
|
+
blocks: [
|
|
108
|
+
placement(2, faq, { question: 'Why?' }),
|
|
109
|
+
placement(1, hero, { headline: 'Hi' }),
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const page = await sites.getPageBySlug(client, {
|
|
116
|
+
siteId: 'site_1',
|
|
117
|
+
slug: 'home',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(operation(request.mock.calls[0])).toBe('GetSitePageBySlug');
|
|
121
|
+
expect(request.mock.calls[0][1]).toEqual({
|
|
122
|
+
siteId: 'site_1',
|
|
123
|
+
slug: 'home',
|
|
124
|
+
});
|
|
125
|
+
expect(page).toEqual({
|
|
126
|
+
id: 'itm_home',
|
|
127
|
+
name: 'Home',
|
|
128
|
+
slug: 'home',
|
|
129
|
+
publishedAt: '2026-09-01T00:00:00Z',
|
|
130
|
+
status: 'Published',
|
|
131
|
+
model: pageType,
|
|
132
|
+
fields: { title: 'Welcome' },
|
|
133
|
+
blocks: [
|
|
134
|
+
{
|
|
135
|
+
id: 'itm_block_1',
|
|
136
|
+
name: 'Hero',
|
|
137
|
+
model: hero,
|
|
138
|
+
fields: { headline: 'Hi' },
|
|
139
|
+
position: 1,
|
|
140
|
+
placementId: 'fv_1',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: 'itm_block_2',
|
|
144
|
+
name: 'FAQ',
|
|
145
|
+
model: faq,
|
|
146
|
+
fields: { question: 'Why?' },
|
|
147
|
+
position: 2,
|
|
148
|
+
placementId: 'fv_2',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('passes includeDrafts through', async () => {
|
|
155
|
+
request.mockResolvedValue({
|
|
156
|
+
node: { __typename: 'Site', pageBySlug: null },
|
|
157
|
+
});
|
|
158
|
+
await sites.getPageBySlug(client, {
|
|
159
|
+
siteId: 'site_1',
|
|
160
|
+
slug: 'draft',
|
|
161
|
+
includeDrafts: true,
|
|
162
|
+
});
|
|
163
|
+
expect(request.mock.calls[0][1]).toEqual({
|
|
164
|
+
siteId: 'site_1',
|
|
165
|
+
slug: 'draft',
|
|
166
|
+
includeDrafts: true,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('returns null for a missing page or a non-Site node', async () => {
|
|
171
|
+
request.mockResolvedValue({
|
|
172
|
+
node: { __typename: 'Site', pageBySlug: null },
|
|
173
|
+
});
|
|
174
|
+
await expect(
|
|
175
|
+
sites.getPageBySlug(client, { siteId: 'site_1', slug: 'x' }),
|
|
176
|
+
).resolves.toBeNull();
|
|
177
|
+
request.mockResolvedValue({ node: null });
|
|
178
|
+
await expect(
|
|
179
|
+
sites.getPageBySlug(client, { siteId: 'x', slug: 'x' }),
|
|
180
|
+
).resolves.toBeNull();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('defaults missing field values to an empty map', async () => {
|
|
184
|
+
request.mockResolvedValue({
|
|
185
|
+
node: {
|
|
186
|
+
__typename: 'Site',
|
|
187
|
+
pageBySlug: {
|
|
188
|
+
...meta(),
|
|
189
|
+
fieldValuesByShortname: null,
|
|
190
|
+
blocks: [placement(1, hero, null as never)],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
const page = await sites.getPageBySlug(client, {
|
|
195
|
+
siteId: 'site_1',
|
|
196
|
+
slug: 'home',
|
|
197
|
+
});
|
|
198
|
+
expect(page?.fields).toEqual({});
|
|
199
|
+
expect(page?.blocks[0].fields).toEqual({});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('listSitePages', () => {
|
|
204
|
+
const blogPost = { id: 'mdl_post', name: 'Blog post', kind: 'page' };
|
|
205
|
+
const header = { id: 'mdl_header', name: 'Header', kind: 'singleton' };
|
|
206
|
+
const pages = [
|
|
207
|
+
meta(),
|
|
208
|
+
meta({ id: 'itm_post', slug: 'hello', model: blogPost }),
|
|
209
|
+
meta({
|
|
210
|
+
id: 'itm_draft',
|
|
211
|
+
slug: 'wip',
|
|
212
|
+
publishedAt: null,
|
|
213
|
+
publishableStatus: 'Draft',
|
|
214
|
+
}),
|
|
215
|
+
meta({
|
|
216
|
+
id: 'itm_later',
|
|
217
|
+
slug: 'later',
|
|
218
|
+
publishedAt: '2027-01-01T00:00:00Z',
|
|
219
|
+
publishableStatus: 'Scheduled',
|
|
220
|
+
}),
|
|
221
|
+
meta({ id: 'itm_header', slug: null, model: header }),
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
beforeEach(() =>
|
|
225
|
+
request.mockResolvedValue({
|
|
226
|
+
node: { __typename: 'Site', id: 'site_1', pages },
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
it('returns published pages only, without singletons', async () => {
|
|
231
|
+
const result = await sites.listSitePages(client, { siteId: 'site_1' });
|
|
232
|
+
expect(operation(request.mock.calls[0])).toBe('ListSitePages');
|
|
233
|
+
expect(request.mock.calls[0][1]).toEqual({ siteId: 'site_1' });
|
|
234
|
+
expect(result.map((p) => p.id)).toEqual(['itm_home', 'itm_post']);
|
|
235
|
+
expect(result[0]).toEqual({
|
|
236
|
+
id: 'itm_home',
|
|
237
|
+
name: 'Home',
|
|
238
|
+
slug: 'home',
|
|
239
|
+
publishedAt: '2026-09-01T00:00:00Z',
|
|
240
|
+
status: 'Published',
|
|
241
|
+
model: pageType,
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('includes drafts and scheduled pages on request', async () => {
|
|
246
|
+
const result = await sites.listSitePages(client, {
|
|
247
|
+
siteId: 'site_1',
|
|
248
|
+
includeDrafts: true,
|
|
249
|
+
});
|
|
250
|
+
expect(result.map((p) => p.id)).toEqual([
|
|
251
|
+
'itm_home',
|
|
252
|
+
'itm_post',
|
|
253
|
+
'itm_draft',
|
|
254
|
+
'itm_later',
|
|
255
|
+
]);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('filters by page type id or name', async () => {
|
|
259
|
+
for (const pageTypeKey of ['mdl_post', 'Blog post']) {
|
|
260
|
+
const result = await sites.listSitePages(client, {
|
|
261
|
+
siteId: 'site_1',
|
|
262
|
+
pageType: pageTypeKey,
|
|
263
|
+
});
|
|
264
|
+
expect(result.map((p) => p.id)).toEqual(['itm_post']);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('returns an empty list when the node is not a Site', async () => {
|
|
269
|
+
request.mockResolvedValue({ node: null });
|
|
270
|
+
await expect(sites.listSitePages(client, { siteId: 'x' })).resolves.toEqual(
|
|
271
|
+
[],
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe('getSingletonBlock', () => {
|
|
277
|
+
it('reads the singleton by shortname and maps it like a page', async () => {
|
|
278
|
+
const header = { id: 'mdl_header', name: 'Header', kind: 'singleton' };
|
|
279
|
+
request.mockResolvedValue({
|
|
280
|
+
node: {
|
|
281
|
+
__typename: 'Site',
|
|
282
|
+
id: 'site_1',
|
|
283
|
+
singletonBlock: {
|
|
284
|
+
...meta({ id: 'itm_header', slug: null, model: header }),
|
|
285
|
+
fieldValuesByShortname: { logo: 'acme.svg' },
|
|
286
|
+
blocks: [],
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
const block = await sites.getSingletonBlock(client, {
|
|
291
|
+
siteId: 'site_1',
|
|
292
|
+
shortname: 'header',
|
|
293
|
+
});
|
|
294
|
+
expect(operation(request.mock.calls[0])).toBe('GetSiteSingletonBlock');
|
|
295
|
+
expect(request.mock.calls[0][1]).toEqual({
|
|
296
|
+
siteId: 'site_1',
|
|
297
|
+
shortname: 'header',
|
|
298
|
+
});
|
|
299
|
+
expect(block).toMatchObject({
|
|
300
|
+
id: 'itm_header',
|
|
301
|
+
model: header,
|
|
302
|
+
fields: { logo: 'acme.svg' },
|
|
303
|
+
blocks: [],
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('returns null when the Site has no such singleton', async () => {
|
|
308
|
+
request.mockResolvedValue({
|
|
309
|
+
node: { __typename: 'Site', singletonBlock: null },
|
|
310
|
+
});
|
|
311
|
+
await expect(
|
|
312
|
+
sites.getSingletonBlock(client, { siteId: 'site_1', shortname: 'nav' }),
|
|
313
|
+
).resolves.toBeNull();
|
|
314
|
+
});
|
|
315
|
+
});
|
package/src/sites.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
GetSiteByDomainDocument,
|
|
4
|
+
GetSiteDocument,
|
|
5
|
+
GetSitePageBySlugDocument,
|
|
6
|
+
GetSiteSingletonBlockDocument,
|
|
7
|
+
ListSitePagesDocument,
|
|
8
|
+
type PublishableStatus,
|
|
9
|
+
type SiteBlockItemFragment,
|
|
10
|
+
type SiteFieldsFragment,
|
|
11
|
+
type SiteModelFieldsFragment,
|
|
12
|
+
type SitePageContentFragment,
|
|
13
|
+
type SitePageMetaFragment,
|
|
14
|
+
} from './generated';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The new CMS: a Site, its page types (page-kind Models), its pages
|
|
18
|
+
* (ModelItems of those Models) and the blocks placed on each page (block-kind
|
|
19
|
+
* ModelItems, in order).
|
|
20
|
+
*
|
|
21
|
+
* This is not the legacy CMS in `cms.ts` (`getPage`/`listPages`, read
|
|
22
|
+
* through `currentWorkspace.project(id:)`): sites still deployed on a legacy
|
|
23
|
+
* Project keep calling those, unchanged. Use this module for Sites.
|
|
24
|
+
*
|
|
25
|
+
* Every read here is public: it works with a `publicToken` client, on the
|
|
26
|
+
* server (RSC) and in the browser.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export type Site = SiteFieldsFragment;
|
|
30
|
+
|
|
31
|
+
/** A Model as the site sees it: a page type, a block kind, a singleton. */
|
|
32
|
+
export type SiteModel = SiteModelFieldsFragment;
|
|
33
|
+
|
|
34
|
+
/** Field values keyed by field shortname: `{ title: '…', cover: {…} }`. */
|
|
35
|
+
export type SiteFields = Record<string, unknown>;
|
|
36
|
+
|
|
37
|
+
export type SiteBlock = {
|
|
38
|
+
/** The block ModelItem. */
|
|
39
|
+
id: string;
|
|
40
|
+
name: string | null;
|
|
41
|
+
/** The block kind (a block-kind Model). */
|
|
42
|
+
model: SiteModel;
|
|
43
|
+
fields: SiteFields;
|
|
44
|
+
position: number;
|
|
45
|
+
/** The placement (the child FieldValue) — what reordering/removing targets. */
|
|
46
|
+
placementId: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type SitePageSummary = {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string | null;
|
|
52
|
+
slug: string | null;
|
|
53
|
+
publishedAt: string | null;
|
|
54
|
+
status: PublishableStatus | null;
|
|
55
|
+
/** The page type (a page-kind Model), or the singleton Model. */
|
|
56
|
+
model: SiteModel;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type SitePage = SitePageSummary & {
|
|
60
|
+
fields: SiteFields;
|
|
61
|
+
/** Ordered by position. */
|
|
62
|
+
blocks: SiteBlock[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// --- mapping ----------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
function toSummary(item: SitePageMetaFragment): SitePageSummary {
|
|
68
|
+
return {
|
|
69
|
+
id: item.id,
|
|
70
|
+
name: item.name ?? null,
|
|
71
|
+
slug: item.slug ?? null,
|
|
72
|
+
publishedAt: item.publishedAt ?? null,
|
|
73
|
+
status: item.publishableStatus ?? null,
|
|
74
|
+
model: item.model,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function toBlock(
|
|
79
|
+
placement: SitePageContentFragment['blocks'][number],
|
|
80
|
+
): SiteBlock {
|
|
81
|
+
const item: SiteBlockItemFragment = placement.modelItem;
|
|
82
|
+
return {
|
|
83
|
+
id: item.id,
|
|
84
|
+
name: item.name ?? null,
|
|
85
|
+
model: item.model,
|
|
86
|
+
fields: item.fieldValuesByShortname ?? {},
|
|
87
|
+
position: placement.position,
|
|
88
|
+
placementId: placement.fieldValueId,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function toPage(item: SitePageContentFragment): SitePage {
|
|
93
|
+
return {
|
|
94
|
+
...toSummary(item),
|
|
95
|
+
fields: item.fieldValuesByShortname ?? {},
|
|
96
|
+
blocks: item.blocks.map(toBlock).sort((a, b) => a.position - b.position),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// --- reads ------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
/** The Site served on `domain` (e.g. `www.acme.org`), or null. */
|
|
103
|
+
export async function getSiteByDomain(
|
|
104
|
+
client: UiduClient,
|
|
105
|
+
variables: { domain: string },
|
|
106
|
+
): Promise<Site | null> {
|
|
107
|
+
const { siteByDomain } = await client.query(
|
|
108
|
+
GetSiteByDomainDocument,
|
|
109
|
+
variables,
|
|
110
|
+
);
|
|
111
|
+
return siteByDomain ?? null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A Site by its id — for previews, where there is no domain to go by. */
|
|
115
|
+
export async function getSite(
|
|
116
|
+
client: UiduClient,
|
|
117
|
+
variables: { id: string },
|
|
118
|
+
): Promise<Site | null> {
|
|
119
|
+
const { node } = await client.query(GetSiteDocument, variables);
|
|
120
|
+
return node?.__typename === 'Site' ? node : null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A page of the Site by slug, with its field values and its ordered blocks.
|
|
125
|
+
* Only published pages unless `includeDrafts`.
|
|
126
|
+
*/
|
|
127
|
+
export async function getPageBySlug(
|
|
128
|
+
client: UiduClient,
|
|
129
|
+
variables: { siteId: string; slug: string; includeDrafts?: boolean },
|
|
130
|
+
): Promise<SitePage | null> {
|
|
131
|
+
const { node } = await client.query(GetSitePageBySlugDocument, variables);
|
|
132
|
+
if (node?.__typename !== 'Site' || !node.pageBySlug) return null;
|
|
133
|
+
return toPage(node.pageBySlug);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The Site's pages, for navigation and sitemaps: published only unless
|
|
138
|
+
* `includeDrafts`, singletons (header, footer) left out.
|
|
139
|
+
*
|
|
140
|
+
* `pageType` keeps the pages of one page type, matched against its Model's
|
|
141
|
+
* id or name.
|
|
142
|
+
*/
|
|
143
|
+
export async function listSitePages(
|
|
144
|
+
client: UiduClient,
|
|
145
|
+
variables: { siteId: string; pageType?: string; includeDrafts?: boolean },
|
|
146
|
+
): Promise<SitePageSummary[]> {
|
|
147
|
+
const { siteId, pageType, includeDrafts = false } = variables;
|
|
148
|
+
const { node } = await client.query(ListSitePagesDocument, { siteId });
|
|
149
|
+
if (node?.__typename !== 'Site') return [];
|
|
150
|
+
return node.pages
|
|
151
|
+
.filter((item) => item.model.kind === 'page')
|
|
152
|
+
.filter((item) => includeDrafts || item.publishableStatus === 'Published')
|
|
153
|
+
.filter(
|
|
154
|
+
(item) =>
|
|
155
|
+
pageType === undefined ||
|
|
156
|
+
item.model.id === pageType ||
|
|
157
|
+
item.model.name === pageType,
|
|
158
|
+
)
|
|
159
|
+
.map(toSummary);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* A singleton of the Site — the header, the footer, the nav — by its Model's
|
|
164
|
+
* shortname, with its field values and blocks.
|
|
165
|
+
*/
|
|
166
|
+
export async function getSingletonBlock(
|
|
167
|
+
client: UiduClient,
|
|
168
|
+
variables: { siteId: string; shortname: string },
|
|
169
|
+
): Promise<SitePage | null> {
|
|
170
|
+
const { node } = await client.query(GetSiteSingletonBlockDocument, variables);
|
|
171
|
+
if (node?.__typename !== 'Site' || !node.singletonBlock) return null;
|
|
172
|
+
return toPage(node.singletonBlock);
|
|
173
|
+
}
|