@unboundcx/sdk 4.1.3 → 4.4.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.
@@ -0,0 +1,44 @@
1
+ // Pure fn, no zod import — this runs before validation inside migrateV1toV2.
2
+ // Mirrors join.js's normalizeJoinSpec() (kept as a standalone duplicate here,
3
+ // not a re-export, so the migrations/ tier stays zod-free per the phase's
4
+ // "migrations run on plain objects" design — see SPEC-PHASE-1.md §2 A14-A18).
5
+ //
6
+ // legacyKind: 'table' | 'component' | 'kanbanChildRecords' — all three raw
7
+ // join shapes observed in the legacy layout builder collapse onto one
8
+ // canonical {childField, parentField} shape:
9
+ // - table / component: {column, value: "{{parentField}}"}
10
+ // - kanban child-records: {childField, parentField} (already un-templated)
11
+ //
12
+ // DEVIATION (Phase 5, SPEC-PHASE-5.md §2.1 step 3): returns
13
+ // {relationship, skipped} instead of a bare relationship object. `skipped`
14
+ // is true when `column` is missing/empty or `value` isn't a clean
15
+ // single-token "{{field}}" template — the spec's explicit "leave untouched"
16
+ // carve-out for joins that can't be synthesized 1:1. Both cases appear in
17
+ // real stored data (app1-api/src/services/layouts/examples.json:865,921 —
18
+ // two "Related Contacts"/"Deal Team" tables with `join.column === ""`), not
19
+ // just the hypothetical concatenated-template case the spec called out —
20
+ // an empty FK column can no more produce a valid JoinSpec.childField
21
+ // (min-length 1) than a non-trivial template can, so both are treated as
22
+ // the same carve-out.
23
+ const MUSTACHE_RE = /^\{\{\s*([\w.]+)\s*\}\}$/;
24
+
25
+ export function normalizeJoin(raw, legacyKind) {
26
+ if (!raw) return { relationship: undefined, skipped: false };
27
+
28
+ // Already canonical (or kanban child-records, which was never templated).
29
+ if (legacyKind === 'kanbanChildRecords' || (raw.childField && !raw.column)) {
30
+ if (!raw.childField) return { relationship: undefined, skipped: true };
31
+ return { relationship: { childField: raw.childField, parentField: raw.parentField || 'id' }, skipped: false };
32
+ }
33
+
34
+ if (!raw.column || typeof raw.value !== 'string') {
35
+ return { relationship: undefined, skipped: true };
36
+ }
37
+
38
+ const match = raw.value.match(MUSTACHE_RE);
39
+ if (!match) {
40
+ return { relationship: undefined, skipped: true };
41
+ }
42
+
43
+ return { relationship: { childField: raw.column, parentField: match[1] }, skipped: false };
44
+ }
@@ -0,0 +1,54 @@
1
+ import { normalizeJoin } from './normalizeJoin.js';
2
+
3
+ // Pure fn, no zod import. Tolerates/normalizes per-mode kanban keys — the 3
4
+ // kanban modes (simple/related/child-records) are described inconsistently
5
+ // across TableEditor.svelte/KanbanEditor.svelte/ComponentEditor.svelte
6
+ // (maps.md §1.7); this fills in the structural keys KanbanConfigSpec
7
+ // (schemas/layouts/kanban.js) always expects (mode, summaries[], actions{})
8
+ // without dropping or rewriting anything mode-specific — additive only.
9
+ //
10
+ // `changes` (optional, Phase 5 addition) collects human-readable entries for
11
+ // the migration-preview tool / backfill-sweep log, same array threaded
12
+ // through migrateV1toV2.js's other normalizers.
13
+ export function normalizeKanban(raw, changes, sectionId) {
14
+ if (!raw) return raw;
15
+
16
+ const mode = raw.mode
17
+ || (raw.childObject ? 'child-records' : (raw.configObject ? 'related' : 'simple'));
18
+ if (!raw.mode && changes) {
19
+ changes.push(`section "${sectionId}" kanban: mode inferred as "${mode}" (not explicitly set)`);
20
+ }
21
+
22
+ const summaries = Array.isArray(raw.summaries) ? raw.summaries : [];
23
+ const actions = raw.actions && typeof raw.actions === 'object' ? raw.actions : {};
24
+
25
+ const next = {
26
+ ...raw,
27
+ mode,
28
+ summaries,
29
+ actions: {
30
+ create: actions.create ?? false,
31
+ edit: actions.edit ?? true,
32
+ delete: actions.delete ?? false,
33
+ cardClick: actions.cardClick || 'modal',
34
+ },
35
+ };
36
+
37
+ // child-records mode's `join` is KanbanChildRecords's own JoinSpec-typed
38
+ // field (schemas/layouts/kanban.js) — canonical-only, same as
39
+ // TableSpec.join. Legacy child-records joins were never templated
40
+ // (kanbanChildRecords fast-path in normalizeJoin), so this only ever
41
+ // fills a missing default parentField; kept here (rather than assumed
42
+ // already-clean) because migrateV1toV2.js can't reach into mode-specific
43
+ // kanban keys itself without duplicating the mode-inference above.
44
+ if (mode === 'child-records' && raw.join) {
45
+ const { relationship, skipped } = normalizeJoin(raw.join, 'kanbanChildRecords');
46
+ if (relationship) {
47
+ next.join = relationship;
48
+ } else if (skipped && changes) {
49
+ changes.push(`section "${sectionId}" kanban: child-records join left as legacy shape (missing childField)`);
50
+ }
51
+ }
52
+
53
+ return next;
54
+ }
@@ -0,0 +1,67 @@
1
+ // Pure fn, no zod import. SPEC-PHASE-5.md §2.1 step 5: promotes qualifying
2
+ // TableSpec entries (already join-normalized by migrateV1toV2.js) to
3
+ // RelatedListSpec, additive alongside `tables[]` — NOT a replacement.
4
+ // `tables[]` stays fully intact so the section keeps validating and nothing
5
+ // is lost if a table doesn't qualify; `relatedLists[]` is a new, parallel
6
+ // key (schemas/layouts/section.js) for the Phase 4 engine's related-list
7
+ // component to read instead of re-deriving the same shape from `tables[]`
8
+ // itself. See section.js's comment at TableSection/TableKanbanSection for
9
+ // why this resolves relatedList.js's "Open Decision #5" as additive rather
10
+ // than folding tables[] away.
11
+ //
12
+ // Promotion criteria (ALL required, per spec):
13
+ // a. table.object differs from the layout's own objectName — a table
14
+ // entry matching the primary object is a plain table, not a related
15
+ // list of itself.
16
+ // b. table.join was normalized to a canonical relationship (i.e. NOT
17
+ // dropped by normalizeJoin's "leave untouched" carve-out).
18
+ // c. table.fields is non-empty — RelatedListSpec.columns.inline requires
19
+ // at least one column (min(1)); an empty fields[] can't produce a
20
+ // valid columns block. Not explicitly named in the spec's 3 criteria,
21
+ // but required by RelatedListSpec's actual zod shape.
22
+ // table.hideRowNumber / `table.header`-style overrides are NOT a gate (per
23
+ // spec: "keep columns: {inline: [...]} verbatim rather than failing the
24
+ // promotion") — this function always emits `columns: {inline: table.fields}`
25
+ // unconditionally, so criterion (c) is the only fields-related check.
26
+ export function promoteRelatedLists(section, objectName, changes) {
27
+ const relatedLists = [];
28
+ const createActions = [];
29
+ const promotedIds = new Set();
30
+
31
+ for (const table of section.tables || []) {
32
+ if (table.object === objectName) continue;
33
+ if (!table.join) continue;
34
+ if (!table.fields || table.fields.length === 0) continue;
35
+
36
+ relatedLists.push({
37
+ id: table.id,
38
+ object: table.object,
39
+ relationship: table.join,
40
+ columns: { inline: table.fields },
41
+ rowActions: {
42
+ open: 'modal',
43
+ quickEdit: table.actions?.edit ? 'modal' : undefined,
44
+ delete: !!table.actions?.delete,
45
+ custom: [],
46
+ },
47
+ defaultSort: table.orderBy,
48
+ filters: table.additionalWhere,
49
+ });
50
+ promotedIds.add(table.id);
51
+ changes.push(
52
+ `section "${section.id}" table "${table.id}": promoted to RelatedListSpec (object="${table.object}")`,
53
+ );
54
+
55
+ if (table.actions?.create) {
56
+ createActions.push({
57
+ id: `${table.id}-related-create`,
58
+ type: 'create',
59
+ target: table.object,
60
+ mode: 'modal',
61
+ placement: 'section',
62
+ });
63
+ }
64
+ }
65
+
66
+ return { relatedLists, createActions, promotedIds };
67
+ }
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+
3
+ // Not resolved here — just shape-checked. Resolution ({{field}} substitution
4
+ // against a record) stays a client/renderer concern (existing replaceVariables()
5
+ // in app1-client/src/utils/index.js), unchanged in this phase.
6
+ export const MustacheTemplate = z.string().min(1);
7
+
8
+ // Matches Section.svelte / TableEditor.svelte conditional-visibility operators
9
+ // (maps.md §1.5) — verified against Row.svelte:79-116's operator switch.
10
+ export const ConditionOperator = z.enum([
11
+ 'eq', 'neq', 'contains', 'startsWith', 'endsWith',
12
+ 'gt', 'gte', 'lt', 'lte', 'isNull', 'isNotNull',
13
+ ]);
14
+
15
+ export const ConditionSpec = z.object({
16
+ field: z.string().min(1),
17
+ operator: ConditionOperator.default('eq'),
18
+ value: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),
19
+ }).refine(
20
+ (v) => ['isNull', 'isNotNull'].includes(v.operator) || v.value !== undefined,
21
+ { message: 'value is required unless operator is isNull/isNotNull', path: ['value'] },
22
+ );
23
+
24
+ export const OrderBySpec = z.object({
25
+ field: z.string().min(1),
26
+ direction: z.enum(['asc', 'desc']).default('asc'),
27
+ });
28
+
29
+ export const HeaderSpec = z.object({
30
+ value: z.string().default(''),
31
+ collapsedValue: z.string().optional(),
32
+ hidden: z.boolean().default(false),
33
+ size: z.enum(['xs', 'sm', 'base', 'lg', 'xl', '2xl', '3xl']).optional(),
34
+ weight: z.enum(['thin', 'light', 'normal', 'medium', 'semibold', 'bold', 'black']).optional(),
35
+ icon: z.string().optional(),
36
+ level: z.enum(['1', '2', '3', '4', '5', '6']).optional(),
37
+ collapsible: z.boolean().optional(),
38
+ });
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+ import { JoinSpec } from './join.js';
3
+ import { OrderBySpec } from './primitives.js';
4
+ import { FormatType } from './format.js';
5
+
6
+ // New primitive, per V2-PLAN's exact definition. Wired into
7
+ // TableSection/TableKanbanSection as `relatedLists[]` (section.js) —
8
+ // additive alongside `tables[]`, not a replacement (SectionSpec.tables[]
9
+ // stays on the legacy-derived TableSpec/JoinSpec shape; RelatedListSpec is a
10
+ // parallel, promoted-subset view). Resolves Open Decision #5 (Phase 5,
11
+ // SPEC-PHASE-5.md §2.1 step 5, migrations/promoteRelatedLists.js) as
12
+ // additive: folding tables[] away entirely would break the old renderer's
13
+ // byte-identical read contract during the v1/v2 soak window.
14
+ const RelatedListInlineColumn = z.object({
15
+ field: z.string().min(1),
16
+ display: z.string().optional(),
17
+ formatType: FormatType.optional(),
18
+ format: z.string().optional(),
19
+ });
20
+
21
+ const RelatedListColumnsSpec = z.union([
22
+ z.object({ compactLayoutRef: z.string().min(1) }),
23
+ z.object({ inline: z.array(RelatedListInlineColumn).min(1) }),
24
+ ]);
25
+
26
+ const RowActionCustomSpec = z.object({
27
+ label: z.string().min(1),
28
+ icon: z.string().optional(),
29
+ action: z.enum(['open', 'edit', 'delete', 'custom']),
30
+ target: z.string().optional(), // custom: workflow/route id resolved by the Phase 4 action registry
31
+ });
32
+
33
+ export const RelatedListSpec = z.object({
34
+ id: z.string().min(1),
35
+ object: z.string().min(1),
36
+ relationship: JoinSpec, // ONE FK declaration — replaces the 3 join semantics for this primitive
37
+ columns: RelatedListColumnsSpec,
38
+ rowActions: z.object({
39
+ open: z.enum(['tab', 'modal', 'peek']).default('modal'),
40
+ quickEdit: z.enum(['inline', 'modal']).optional(), // 'modal' = opens this object's compact layout
41
+ delete: z.boolean().default(false),
42
+ custom: z.array(RowActionCustomSpec).default([]),
43
+ }).default({ open: 'modal', delete: false, custom: [] }),
44
+ emptyState: z.object({ message: z.string().optional(), icon: z.string().optional() }).optional(),
45
+ defaultSort: OrderBySpec.optional(),
46
+ filters: z.record(z.string()).optional(), // "<operator>::<term>" DSL — same as buildObjectQuery.js
47
+ pageSize: z.number().int().positive().max(200).default(25),
48
+ });
@@ -0,0 +1,100 @@
1
+ import { z } from 'zod';
2
+ import { HeaderSpec, ConditionSpec, OrderBySpec } from './primitives.js';
3
+ import { FieldSpec } from './field.js';
4
+ import { JoinSpec } from './join.js';
5
+ import { FormatType } from './format.js';
6
+ import { KanbanConfigSpec } from './kanban.js';
7
+ import { RelatedListSpec } from './relatedList.js';
8
+
9
+ const TableFieldSpec = z.object({
10
+ field: z.string().min(1),
11
+ display: z.string().default(''),
12
+ hidden: z.boolean().default(false),
13
+ sortable: z.boolean().default(true),
14
+ type: z.enum(['link']).optional(),
15
+ link: z.string().optional(),
16
+ linkField: z.string().optional(),
17
+ linkObject: z.string().optional(),
18
+ formatType: FormatType.optional(),
19
+ format: z.string().optional(),
20
+ relatedKey: z.string().optional(),
21
+ relatedObject: z.string().optional(),
22
+ }).refine((v) => v.type !== 'link' || (v.link && v.linkField && v.linkObject), {
23
+ message: 'type:"link" requires link, linkField, and linkObject',
24
+ });
25
+
26
+ const TableSpec = z.object({
27
+ id: z.string().min(1),
28
+ object: z.string().min(1),
29
+ join: JoinSpec.optional(), // absent = top-level list table (no parent record)
30
+ fields: z.array(TableFieldSpec).default([]),
31
+ header: HeaderSpec.partial().optional(),
32
+ actions: z.object({
33
+ edit: z.boolean().default(true),
34
+ create: z.boolean().default(false),
35
+ delete: z.boolean().default(false),
36
+ hideOnCreate: z.boolean().default(false),
37
+ cardClick: z.enum(['tab', 'modal']).default('tab'),
38
+ }).default({}),
39
+ orderBy: OrderBySpec.optional(),
40
+ additionalWhere: z.record(z.string()).optional(),
41
+ hideOnCreate: z.boolean().default(false),
42
+ });
43
+
44
+ const RowSpec = z.object({
45
+ id: z.string().min(1),
46
+ columns: z.array(FieldSpec),
47
+ });
48
+
49
+ const BaseSection = z.object({
50
+ id: z.string().min(1),
51
+ header: HeaderSpec.default({}),
52
+ editable: z.boolean().default(true),
53
+ hideOnCreate: z.boolean().default(false),
54
+ autoCollapse: z.boolean().default(false),
55
+ showCollapse: z.boolean().default(false),
56
+ conditions: ConditionSpec.optional(),
57
+ });
58
+
59
+ const ContentSection = BaseSection.extend({
60
+ type: z.literal('content'),
61
+ rows: z.array(RowSpec).default([]),
62
+ });
63
+
64
+ // `relatedLists` (Phase 5 addition, SPEC-PHASE-5.md §2.1 step 5): resolves
65
+ // relatedList.js's "Open Decision #5" as ADDITIVE, not a fold — `tables[]`
66
+ // stays the full, unmodified source of truth (old renderer + Phase 4's
67
+ // plain-table view both read it); `relatedLists[]` is a parallel,
68
+ // promoted-subset view for Phase 4's dedicated related-list component,
69
+ // populated by migrations/promoteRelatedLists.js for qualifying entries
70
+ // only. Never required, defaults empty.
71
+ const TableSection = BaseSection.extend({
72
+ type: z.literal('table'),
73
+ tableLayout: z.enum(['full-width', 'two-columns']).default('full-width'),
74
+ tables: z.array(TableSpec).min(1),
75
+ relatedLists: z.array(RelatedListSpec).default([]),
76
+ });
77
+
78
+ const KanbanSection = BaseSection.extend({
79
+ type: z.literal('kanban'),
80
+ kanban: KanbanConfigSpec,
81
+ });
82
+
83
+ const TableKanbanSection = BaseSection.extend({
84
+ type: z.literal('table-kanban'),
85
+ defaultView: z.enum(['table', 'kanban']).default('table'),
86
+ tableLayout: z.enum(['full-width', 'two-columns']).default('full-width'),
87
+ tables: z.array(TableSpec).min(1),
88
+ kanban: KanbanConfigSpec,
89
+ relatedLists: z.array(RelatedListSpec).default([]),
90
+ });
91
+
92
+ // Note: this schema has no branch for legacy single-table
93
+ // section.object/fields/join/actions (no tables[]) — those docs must pass
94
+ // through migrateV1toV2 (which auto-wraps them into tables:[{...}], per
95
+ // V2-PLAN §6) before they'll validate. This is deliberate: it gives Phase 3's
96
+ // "delete TableEditor's legacy code path" work a schema-level forcing
97
+ // function.
98
+ export const SectionSpec = z.discriminatedUnion('type', [
99
+ ContentSection, TableSection, KanbanSection, TableKanbanSection,
100
+ ]);
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+ import { MustacheTemplate } from './primitives.js';
3
+
4
+ // Canonicalizes away the `url` string / `queryConfig` object duplication and
5
+ // the `response` vs `responseMapping` dual mapping (maps.md §1.9). Design
6
+ // decision: v2 canonical docs store `queryConfig` only — `url` is never
7
+ // authored or persisted; the client's shared selectDynamic resolver (Phase 4,
8
+ // src/lib/layout-engine/) regenerates the request URL from `queryConfig` at
9
+ // render time, replacing the 3x-duplicated buildSelectDynamicUrl logic
10
+ // (Column.svelte:196-245, ModernField.svelte:222-269, WorkflowField.svelte:174-214).
11
+ // This is a schema-level decision Phase 4 must honor; flagged in Risks.
12
+ export const ResponseMappingSpec = z.object({
13
+ name: z.string().min(1),
14
+ value: z.string().min(1),
15
+ });
16
+
17
+ export const SelectDynamicQueryConfig = z.object({
18
+ object: z.string().min(1),
19
+ select: z.array(z.string()).default(['id', 'name']),
20
+ searchField: z.string().default('name'),
21
+ searchOperator: z.enum(['contains', 'startsWith', 'endsWith', 'eq']).default('contains'),
22
+ valueField: z.string().default('id'), // canonical name for legacy valueColumn
23
+ displayTemplate: MustacheTemplate.default('{{name}}'),
24
+ limit: z.number().int().positive().max(200).default(25),
25
+ additionalWhere: z.record(z.string()).optional(), // "<operator>::<term>" DSL, same as buildObjectQuery.js
26
+ orderByField: z.string().optional(),
27
+ orderByDirection: z.enum(['asc', 'desc']).default('asc'),
28
+ });
29
+
30
+ export const SelectDynamicSpec = z.object({
31
+ queryConfig: SelectDynamicQueryConfig,
32
+ responseMapping: ResponseMappingSpec.default({ name: 'name', value: 'id' }),
33
+ multiple: z.boolean().default(false),
34
+ clearable: z.boolean().default(true),
35
+ searchable: z.boolean().default(true),
36
+ preloadOptions: z.boolean().default(false),
37
+ initialSearchQuery: z.string().optional(),
38
+ initialLoadLimit: z.number().int().positive().optional(),
39
+ fetchOptions: z.object({ credentials: z.string().optional() }).optional(),
40
+ });
@@ -0,0 +1,18 @@
1
+ import { LayoutDoc } from './layoutDoc.js';
2
+ import { CompactLayoutDoc } from './compact.js';
3
+
4
+ // type: explicit override; falls back to doc.type. Compact docs (type:'compact')
5
+ // validate against CompactLayoutDoc; everything else against LayoutDoc.
6
+ export function validateLayoutDoc(rawDoc, { type } = {}) {
7
+ const docType = type || rawDoc?.type;
8
+ const schema = docType === 'compact' ? CompactLayoutDoc : LayoutDoc;
9
+ const result = schema.safeParse(rawDoc);
10
+ if (result.success) {
11
+ return { valid: true, errors: [], data: result.data };
12
+ }
13
+ return {
14
+ valid: false,
15
+ errors: result.error.issues.map((i) => ({ path: i.path.join('.'), message: i.message })),
16
+ data: null,
17
+ };
18
+ }
@@ -1,6 +1,10 @@
1
+ import * as layoutSchemas from '../schemas/layouts/index.js';
2
+
1
3
  export class LayoutsService {
2
4
  constructor(sdk) {
3
5
  this.sdk = sdk;
6
+ this.schema = layoutSchemas; // sdk.layouts.schema.{LayoutDoc, validateLayoutDoc, migrateLayoutSchema, ...}
7
+ this.assignments = new LayoutAssignmentsService(sdk); // sdk.layouts.assignments.{list,create,update,delete}
4
8
  }
5
9
 
6
10
  async get(objectName, id, query = {}) {
@@ -86,10 +90,147 @@ export class LayoutsService {
86
90
  };
87
91
 
88
92
  const result = await this.sdk._fetch(
89
- '/layouts/dynamic-select-search',
93
+ '/layouts/selectDynamic/search',
90
94
  'GET',
91
95
  params,
92
96
  );
93
97
  return result;
94
98
  }
99
+
100
+ async resolve({ object, kind, recordId, recordTypeId, asUser } = {}) {
101
+ this.sdk.validateParams(
102
+ { object, kind },
103
+ {
104
+ object: { type: 'string', required: true },
105
+ kind: { type: 'string', required: true },
106
+ recordId: { type: 'string', required: false },
107
+ recordTypeId: { type: 'string', required: false },
108
+ asUser: { type: 'string', required: false },
109
+ },
110
+ );
111
+
112
+ const params = {
113
+ query: { object, kind, recordId, recordTypeId, asUser },
114
+ };
115
+
116
+ const result = await this.sdk._fetch('/layouts/resolve', 'GET', params);
117
+ return result;
118
+ }
119
+
120
+ async getVersions(layoutId) {
121
+ this.sdk.validateParams(
122
+ { layoutId },
123
+ { layoutId: { type: 'string', required: true } },
124
+ );
125
+
126
+ const result = await this.sdk._fetch(`/layouts/${layoutId}/versions`, 'GET', {});
127
+ return result;
128
+ }
129
+
130
+ async getForEdit(layoutId) {
131
+ this.sdk.validateParams(
132
+ { layoutId },
133
+ { layoutId: { type: 'string', required: true } },
134
+ );
135
+
136
+ const result = await this.sdk._fetch(`/layouts/${layoutId}/edit`, 'GET', {});
137
+ return result;
138
+ }
139
+
140
+ async publish(layoutId, { changeNote } = {}) {
141
+ this.sdk.validateParams(
142
+ { layoutId },
143
+ { layoutId: { type: 'string', required: true } },
144
+ );
145
+
146
+ const params = {
147
+ body: { changeNote },
148
+ };
149
+
150
+ const result = await this.sdk._fetch(`/layouts/${layoutId}/publish`, 'POST', params);
151
+ return result;
152
+ }
153
+
154
+ async rollback(layoutId, version) {
155
+ this.sdk.validateParams(
156
+ { layoutId, version },
157
+ {
158
+ layoutId: { type: 'string', required: true },
159
+ version: { type: 'number', required: true },
160
+ },
161
+ );
162
+
163
+ const result = await this.sdk._fetch(
164
+ `/layouts/${layoutId}/versions/${version}/rollback`,
165
+ 'POST',
166
+ {},
167
+ );
168
+ return result;
169
+ }
170
+ }
171
+
172
+ export class LayoutAssignmentsService {
173
+ constructor(sdk) {
174
+ this.sdk = sdk;
175
+ }
176
+
177
+ async list({ objectName, kind } = {}) {
178
+ this.sdk.validateParams(
179
+ { objectName, kind },
180
+ {
181
+ objectName: { type: 'string', required: true },
182
+ kind: { type: 'string', required: true },
183
+ },
184
+ );
185
+
186
+ const params = {
187
+ query: { objectName, kind },
188
+ };
189
+
190
+ const result = await this.sdk._fetch('/layouts/assignments', 'GET', params);
191
+ return result;
192
+ }
193
+
194
+ async create({ objectName, kind, recordTypeId, audienceType, audienceId, layoutId, priority } = {}) {
195
+ this.sdk.validateParams(
196
+ { objectName, kind, audienceType, layoutId },
197
+ {
198
+ objectName: { type: 'string', required: true },
199
+ kind: { type: 'string', required: true },
200
+ audienceType: { type: 'string', required: true },
201
+ layoutId: { type: 'string', required: true },
202
+ },
203
+ );
204
+
205
+ const params = {
206
+ body: { objectName, kind, recordTypeId, audienceType, audienceId, layoutId, priority },
207
+ };
208
+
209
+ const result = await this.sdk._fetch('/layouts/assignments', 'POST', params);
210
+ return result;
211
+ }
212
+
213
+ async update(id, updates) {
214
+ this.sdk.validateParams(
215
+ { id },
216
+ { id: { type: 'string', required: true } },
217
+ );
218
+
219
+ const params = {
220
+ body: updates,
221
+ };
222
+
223
+ const result = await this.sdk._fetch(`/layouts/assignments/${id}`, 'PUT', params);
224
+ return result;
225
+ }
226
+
227
+ async delete(id) {
228
+ this.sdk.validateParams(
229
+ { id },
230
+ { id: { type: 'string', required: true } },
231
+ );
232
+
233
+ const result = await this.sdk._fetch(`/layouts/assignments/${id}`, 'DELETE', {});
234
+ return result;
235
+ }
95
236
  }