@uidu/client 3.9.0 → 3.11.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.
@@ -1,4 +1,4 @@
1
- export { UiduClient, createClient } from "./client.js";
1
+ export { UiduClient, createClient, fromBridge } from "./client.js";
2
2
  export { UiduError } from "./types.js";
3
3
  export type { UiduClientConfig, UiduErrorOptions } from "./types.js";
4
4
  export { paginate } from "./utils/paginate.js";
@@ -7,10 +7,13 @@ export { normalizeFieldValueContent, normalizeFieldValuesAttributes, } from "./u
7
7
  export { ListApplicationsDocument, ListBookingsDocument, ListCalendarsDocument, ListCalendarEventsDocument, ListCallsDocument, ListCampaignsDocument, ListEmailCampaignsDocument, ListCoursesDocument, ListDealsDocument, ListDonationCampaignsDocument, ListEmployeesDocument, ListEnrollmentsDocument, ListEventsDocument, ListFormsDocument, ListKbArticlesDocument, ListKbCollectionsDocument, ListLecturesDocument, ListPagesDocument, ListStoriesDocument, } from "./generated/index.js";
8
8
  export { getPage, listPages, getTemplate, createProject, createPage, createPageBlock, createFieldValue, listProjects, } from "./cms.js";
9
9
  export type { Page, Template } from "./cms.js";
10
+ export { getSiteByDomain, getSite, getPageBySlug, listSitePages, getSingletonBlock, } from "./sites.js";
11
+ export type { Site, SiteModel, SiteFields, SiteBlock, SitePage, SitePageSummary, } from "./sites.js";
10
12
  export { createWorkspace, generateWorkspaceApiCredentials } from "./system.js";
11
13
  export { createSpace } from "./spaces.js";
12
14
  export { createTask } from "./tasks.js";
13
15
  export { createNote } from "./notes.js";
16
+ export { executeAction } from "./actions.js";
14
17
  export { createBenefit } from "./benefits.js";
15
18
  export { createBenefitEnrollment } from "./benefit-enrollments.js";
16
19
  export { createCourse, updateCourse, deleteCourse, createForm, updateForm, deleteForm, createContact, deleteContact, createDeal, updateDeal, createKbCollection, updateKbCollection, deleteKbCollection, createKbArticle, updateKbArticle, deleteKbArticle, createChannel, updateChannel, deleteChannel, updateEvent, updateStory, updateDonationCampaign, deleteDonationCampaign, updateTask, deleteTask, updateNote, deleteNote, updateSpace, deleteSpace, createEmployee, updateEmployee, createEmployment, updateEmployment, deleteEmployment, terminateEmployment, createCompensation, updateCompensation, deleteCompensation, } from "./mutations.js";
@@ -44,3 +47,5 @@ export { getContact, listContacts, getDeal, listDeals } from "./contacts.js";
44
47
  export type { Contact, Deal } from "./contacts.js";
45
48
  export { getKbArticle, listKbArticles, getKbCollection, listKbCollections, } from "./kb.js";
46
49
  export type { KbArticle, KbCollection } from "./kb.js";
50
+ export { listModels, getModel, listModelItems, getModelItem, createModel, updateModel, createField, updateField, deleteField, createFieldOption, updateFieldOption, deleteFieldOption, createModelItem, updateModelItem, deleteModelItem, updateFieldValue, deleteFieldValue, toFieldValuesAttributes, ensureModel, } from "./models.js";
51
+ export type { Model, ModelField, ModelFieldOption, ModelItem, EnsureModelOptions, } from "./models.js";
@@ -0,0 +1,326 @@
1
+ import type { UiduClient } from "./client.js";
2
+ import { type CreateFieldMutationVariables, type CreateFieldOptionMutationVariables, type CreateModelItemMutationVariables, type CreateModelMutationVariables, type DeleteFieldMutationVariables, type DeleteFieldOptionMutationVariables, type DeleteFieldValueMutationVariables, type DeleteModelItemMutationVariables, type FieldKind, type FieldValueAttributes, type ModelFieldFragment, type ModelFieldOptionFragment, type ModelItemFieldsFragment, type ModelSchemaFragment, type SearchParams, type UpdateFieldMutationVariables, type UpdateFieldOptionMutationVariables, type UpdateFieldValueMutationVariables, type UpdateModelItemMutationVariables, type UpdateModelMutationVariables } from "./generated/index.js";
3
+ /**
4
+ * The data engine a custom app keeps its records in: the Models of its own
5
+ * WorkspaceApp, their Fields, and their ModelItems.
6
+ *
7
+ * Built for a client made from a custom app session (`fromBridge` +
8
+ * `@uidu/app-bridge`), whose token may only call `node`/`nodes` and the
9
+ * mutations below, on records of its own WorkspaceApp — so every read goes
10
+ * through `node(id:)`, starting from `bridge.context.workspaceApp.id`. Works
11
+ * the same with a Bearer `apiKey`.
12
+ *
13
+ * Mutations return the payload as-is (including `errors`) rather than
14
+ * throwing, like the rest of the authoring slice. Schema writes (models,
15
+ * fields, options) are interim: step 3 of the custom apps spec moves them to
16
+ * an install-time manifest.
17
+ */
18
+ export type Model = ModelSchemaFragment;
19
+ export type ModelField = ModelFieldFragment;
20
+ export type ModelFieldOption = ModelFieldOptionFragment;
21
+ export type ModelItem = ModelItemFieldsFragment;
22
+ /** The models of a WorkspaceApp, with their fields. */
23
+ export declare function listModels(client: UiduClient, variables: {
24
+ workspaceAppId: string;
25
+ }): Promise<Model[]>;
26
+ export declare function getModel(client: UiduClient, variables: {
27
+ id: string;
28
+ }): Promise<Model | null>;
29
+ /**
30
+ * A model's items. Each carries `fieldValuesByShortname` — `{ room: 'Aula
31
+ * Magna', when: '…' }` — the easiest shape to read values from.
32
+ */
33
+ export declare function listModelItems(client: UiduClient, variables: {
34
+ modelId: string;
35
+ params?: SearchParams;
36
+ }): Promise<ModelItem[]>;
37
+ export declare function getModelItem(client: UiduClient, variables: {
38
+ id: string;
39
+ }): Promise<(ModelItem & {
40
+ model: {
41
+ id: string;
42
+ };
43
+ }) | null>;
44
+ export declare function createModel(client: UiduClient, variables: CreateModelMutationVariables): Promise<{
45
+ __typename?: "CreateModelPayload";
46
+ model?: {
47
+ __typename?: "Model";
48
+ id: string;
49
+ name?: string | null;
50
+ namePlural?: string | null;
51
+ fieldList?: Array<{
52
+ __typename?: "Field";
53
+ id: string;
54
+ name?: string | null;
55
+ shortname?: string | null;
56
+ kind?: FieldKind | null;
57
+ required?: boolean | null;
58
+ position: number;
59
+ optionList?: Array<{
60
+ __typename?: "FieldOption";
61
+ id: string;
62
+ name?: string | null;
63
+ color?: string | null;
64
+ position: number;
65
+ }> | null;
66
+ }> | null;
67
+ } | null;
68
+ errors: Array<{
69
+ __typename?: "Error";
70
+ key: string;
71
+ name: string;
72
+ type: string;
73
+ }>;
74
+ } | null>;
75
+ export declare function updateModel(client: UiduClient, variables: UpdateModelMutationVariables): Promise<{
76
+ __typename?: "UpdateModelPayload";
77
+ model?: {
78
+ __typename?: "Model";
79
+ id: string;
80
+ name?: string | null;
81
+ namePlural?: string | null;
82
+ fieldList?: Array<{
83
+ __typename?: "Field";
84
+ id: string;
85
+ name?: string | null;
86
+ shortname?: string | null;
87
+ kind?: FieldKind | null;
88
+ required?: boolean | null;
89
+ position: number;
90
+ optionList?: Array<{
91
+ __typename?: "FieldOption";
92
+ id: string;
93
+ name?: string | null;
94
+ color?: string | null;
95
+ position: number;
96
+ }> | null;
97
+ }> | null;
98
+ } | null;
99
+ errors: Array<{
100
+ __typename?: "Error";
101
+ key: string;
102
+ name: string;
103
+ type: string;
104
+ }>;
105
+ } | null>;
106
+ /**
107
+ * Pass `fieldableId` (the model) with `fieldableType: 'Model'`: a custom app
108
+ * may only name a type that matches the record it loads.
109
+ */
110
+ export declare function createField(client: UiduClient, variables: CreateFieldMutationVariables): Promise<{
111
+ __typename?: "CreateFieldPayload";
112
+ field?: {
113
+ __typename?: "Field";
114
+ id: string;
115
+ name?: string | null;
116
+ shortname?: string | null;
117
+ kind?: FieldKind | null;
118
+ required?: boolean | null;
119
+ position: number;
120
+ optionList?: Array<{
121
+ __typename?: "FieldOption";
122
+ id: string;
123
+ name?: string | null;
124
+ color?: string | null;
125
+ position: number;
126
+ }> | null;
127
+ } | null;
128
+ errors: Array<{
129
+ __typename?: "Error";
130
+ key: string;
131
+ name: string;
132
+ type: string;
133
+ }>;
134
+ } | null>;
135
+ export declare function updateField(client: UiduClient, variables: UpdateFieldMutationVariables): Promise<{
136
+ __typename?: "UpdateFieldPayload";
137
+ field?: {
138
+ __typename?: "Field";
139
+ id: string;
140
+ name?: string | null;
141
+ shortname?: string | null;
142
+ kind?: FieldKind | null;
143
+ required?: boolean | null;
144
+ position: number;
145
+ optionList?: Array<{
146
+ __typename?: "FieldOption";
147
+ id: string;
148
+ name?: string | null;
149
+ color?: string | null;
150
+ position: number;
151
+ }> | null;
152
+ } | null;
153
+ errors: Array<{
154
+ __typename?: "Error";
155
+ key: string;
156
+ name: string;
157
+ type: string;
158
+ }>;
159
+ } | null>;
160
+ export declare function deleteField(client: UiduClient, variables: DeleteFieldMutationVariables): Promise<{
161
+ __typename?: "DeleteFieldPayload";
162
+ field?: {
163
+ __typename?: "Field";
164
+ id: string;
165
+ } | null;
166
+ errors: Array<{
167
+ __typename?: "Error";
168
+ key: string;
169
+ name: string;
170
+ type: string;
171
+ }>;
172
+ } | null>;
173
+ export declare function createFieldOption(client: UiduClient, variables: CreateFieldOptionMutationVariables): Promise<{
174
+ __typename?: "CreateFieldOptionPayload";
175
+ fieldOption?: {
176
+ __typename?: "FieldOption";
177
+ id: string;
178
+ name?: string | null;
179
+ color?: string | null;
180
+ position: number;
181
+ } | null;
182
+ errors: Array<{
183
+ __typename?: "Error";
184
+ key: string;
185
+ name: string;
186
+ type: string;
187
+ }>;
188
+ } | null>;
189
+ export declare function updateFieldOption(client: UiduClient, variables: UpdateFieldOptionMutationVariables): Promise<{
190
+ __typename?: "UpdateFieldOptionPayload";
191
+ fieldOption?: {
192
+ __typename?: "FieldOption";
193
+ id: string;
194
+ name?: string | null;
195
+ color?: string | null;
196
+ position: number;
197
+ } | null;
198
+ errors: Array<{
199
+ __typename?: "Error";
200
+ key: string;
201
+ name: string;
202
+ type: string;
203
+ }>;
204
+ } | null>;
205
+ export declare function deleteFieldOption(client: UiduClient, variables: DeleteFieldOptionMutationVariables): Promise<{
206
+ __typename?: "DeleteFieldOptionPayload";
207
+ fieldOption?: {
208
+ __typename?: "FieldOption";
209
+ id: string;
210
+ } | null;
211
+ errors: Array<{
212
+ __typename?: "Error";
213
+ key: string;
214
+ name: string;
215
+ type: string;
216
+ }>;
217
+ } | null>;
218
+ /**
219
+ * Pass `attributes.modelId` and `attributes.fieldValuesAttributes` — build
220
+ * the latter by shortname with {@link toFieldValuesAttributes}.
221
+ */
222
+ export declare function createModelItem(client: UiduClient, variables: CreateModelItemMutationVariables): Promise<{
223
+ __typename?: "CreateModelItemPayload";
224
+ modelItem?: {
225
+ __typename?: "ModelItem";
226
+ id: string;
227
+ name?: string | null;
228
+ fieldValuesByShortname?: any | null;
229
+ createdAt: any;
230
+ updatedAt: any;
231
+ } | null;
232
+ errors: Array<{
233
+ __typename?: "Error";
234
+ key: string;
235
+ name: string;
236
+ type: string;
237
+ }>;
238
+ } | null>;
239
+ export declare function updateModelItem(client: UiduClient, variables: UpdateModelItemMutationVariables): Promise<{
240
+ __typename?: "UpdateModelItemPayload";
241
+ modelItem?: {
242
+ __typename?: "ModelItem";
243
+ id: string;
244
+ name?: string | null;
245
+ fieldValuesByShortname?: any | null;
246
+ createdAt: any;
247
+ updatedAt: any;
248
+ } | null;
249
+ errors: Array<{
250
+ __typename?: "Error";
251
+ key: string;
252
+ name: string;
253
+ type: string;
254
+ }>;
255
+ } | null>;
256
+ export declare function deleteModelItem(client: UiduClient, variables: DeleteModelItemMutationVariables): Promise<{
257
+ __typename?: "DeleteModelItemPayload";
258
+ modelItem?: {
259
+ __typename?: "ModelItem";
260
+ id: string;
261
+ } | null;
262
+ errors: Array<{
263
+ __typename?: "Error";
264
+ key: string;
265
+ name: string;
266
+ type: string;
267
+ }>;
268
+ } | null>;
269
+ export declare function updateFieldValue(client: UiduClient, variables: UpdateFieldValueMutationVariables): Promise<{
270
+ __typename?: "UpdateFieldValuePayload";
271
+ fieldValue?: {
272
+ __typename?: "FieldValue";
273
+ id: string;
274
+ content?: any | null;
275
+ } | null;
276
+ errors: Array<{
277
+ __typename?: "Error";
278
+ key: string;
279
+ name: string;
280
+ type: string;
281
+ }>;
282
+ } | null>;
283
+ export declare function deleteFieldValue(client: UiduClient, variables: DeleteFieldValueMutationVariables): Promise<{
284
+ __typename?: "DeleteFieldValuePayload";
285
+ fieldValue?: {
286
+ __typename?: "FieldValue";
287
+ id: string;
288
+ } | null;
289
+ errors: Array<{
290
+ __typename?: "Error";
291
+ key: string;
292
+ name: string;
293
+ type: string;
294
+ }>;
295
+ } | null>;
296
+ /**
297
+ * `{ room: 'Aula Magna' }` → `[{ fieldId: '<id of room>', content: { value:
298
+ * 'Aula Magna' } }]`, for `createModelItem` / `updateModelItem`. Throws on a
299
+ * shortname the model doesn't have; skips `undefined` values.
300
+ */
301
+ export declare function toFieldValuesAttributes(model: {
302
+ fieldList?: ReadonlyArray<{
303
+ id: string;
304
+ shortname?: string | null;
305
+ }> | null;
306
+ }, values: Record<string, unknown>): FieldValueAttributes[];
307
+ export interface EnsureModelOptions {
308
+ workspaceAppId: string;
309
+ /** Matched against existing models by name. */
310
+ name: string;
311
+ namePlural?: string;
312
+ /** Matched by shortname; missing ones are created, extra ones left alone. */
313
+ fields: ReadonlyArray<{
314
+ shortname: string;
315
+ name: string;
316
+ kind: FieldKind | `${FieldKind}`;
317
+ required?: boolean;
318
+ }>;
319
+ }
320
+ /**
321
+ * Find the app's model by name, or create it — and any of `fields` it lacks.
322
+ * Returns the model with all its fields. What a custom app runs on its first
323
+ * load until schemas come from an install-time manifest (custom apps spec,
324
+ * step 3). Throws a `UiduError` (`MUTATION_ERROR`) when a write is refused.
325
+ */
326
+ export declare function ensureModel(client: UiduClient, options: EnsureModelOptions): Promise<Model>;
@@ -0,0 +1,81 @@
1
+ import type { UiduClient } from "./client.js";
2
+ import { type PublishableStatus, type SiteFieldsFragment, type SiteModelFieldsFragment } from "./generated/index.js";
3
+ /**
4
+ * The new CMS: a Site, its page types (page-kind Models), its pages
5
+ * (ModelItems of those Models) and the blocks placed on each page (block-kind
6
+ * ModelItems, in order).
7
+ *
8
+ * This is not the legacy CMS in `cms.ts` (`getPage`/`listPages`, read
9
+ * through `currentWorkspace.project(id:)`): sites still deployed on a legacy
10
+ * Project keep calling those, unchanged. Use this module for Sites.
11
+ *
12
+ * Every read here is public: it works with a `publicToken` client, on the
13
+ * server (RSC) and in the browser.
14
+ */
15
+ export type Site = SiteFieldsFragment;
16
+ /** A Model as the site sees it: a page type, a block kind, a singleton. */
17
+ export type SiteModel = SiteModelFieldsFragment;
18
+ /** Field values keyed by field shortname: `{ title: '…', cover: {…} }`. */
19
+ export type SiteFields = Record<string, unknown>;
20
+ export type SiteBlock = {
21
+ /** The block ModelItem. */
22
+ id: string;
23
+ name: string | null;
24
+ /** The block kind (a block-kind Model). */
25
+ model: SiteModel;
26
+ fields: SiteFields;
27
+ position: number;
28
+ /** The placement (the child FieldValue) — what reordering/removing targets. */
29
+ placementId: string;
30
+ };
31
+ export type SitePageSummary = {
32
+ id: string;
33
+ name: string | null;
34
+ slug: string | null;
35
+ publishedAt: string | null;
36
+ status: PublishableStatus | null;
37
+ /** The page type (a page-kind Model), or the singleton Model. */
38
+ model: SiteModel;
39
+ };
40
+ export type SitePage = SitePageSummary & {
41
+ fields: SiteFields;
42
+ /** Ordered by position. */
43
+ blocks: SiteBlock[];
44
+ };
45
+ /** The Site served on `domain` (e.g. `www.acme.org`), or null. */
46
+ export declare function getSiteByDomain(client: UiduClient, variables: {
47
+ domain: string;
48
+ }): Promise<Site | null>;
49
+ /** A Site by its id — for previews, where there is no domain to go by. */
50
+ export declare function getSite(client: UiduClient, variables: {
51
+ id: string;
52
+ }): Promise<Site | null>;
53
+ /**
54
+ * A page of the Site by slug, with its field values and its ordered blocks.
55
+ * Only published pages unless `includeDrafts`.
56
+ */
57
+ export declare function getPageBySlug(client: UiduClient, variables: {
58
+ siteId: string;
59
+ slug: string;
60
+ includeDrafts?: boolean;
61
+ }): Promise<SitePage | null>;
62
+ /**
63
+ * The Site's pages, for navigation and sitemaps: published only unless
64
+ * `includeDrafts`, singletons (header, footer) left out.
65
+ *
66
+ * `pageType` keeps the pages of one page type, matched against its Model's
67
+ * id or name.
68
+ */
69
+ export declare function listSitePages(client: UiduClient, variables: {
70
+ siteId: string;
71
+ pageType?: string;
72
+ includeDrafts?: boolean;
73
+ }): Promise<SitePageSummary[]>;
74
+ /**
75
+ * A singleton of the Site — the header, the footer, the nav — by its Model's
76
+ * shortname, with its field values and blocks.
77
+ */
78
+ export declare function getSingletonBlock(client: UiduClient, variables: {
79
+ siteId: string;
80
+ shortname: string;
81
+ }): Promise<SitePage | null>;
@@ -1,7 +1,14 @@
1
1
  export interface UiduClientConfig {
2
- workspace: string;
2
+ /** Builds the default endpoint. Not needed when `endpoint` is given. */
3
+ workspace?: string;
3
4
  publicToken?: string;
4
5
  apiKey?: string;
6
+ /**
7
+ * A Bearer token fetched per request, for tokens that expire — a custom
8
+ * app's session from `@uidu/app-bridge` (see `fromBridge`). Takes
9
+ * precedence over `apiKey`.
10
+ */
11
+ getToken?: () => Promise<string>;
5
12
  endpoint?: string;
6
13
  headers?: Record<string, string>;
7
14
  }