@elevasis/core 0.9.0 → 0.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.
Files changed (49) hide show
  1. package/dist/index.d.ts +67 -159
  2. package/dist/index.js +321 -613
  3. package/dist/organization-model/index.d.ts +67 -159
  4. package/dist/organization-model/index.js +321 -613
  5. package/dist/test-utils/index.d.ts +615 -316
  6. package/dist/test-utils/index.js +20390 -2
  7. package/package.json +3 -3
  8. package/src/__tests__/template-core-compatibility.test.ts +73 -91
  9. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +62 -148
  10. package/src/organization-model/README.md +101 -97
  11. package/src/organization-model/__tests__/domains/resource-mappings.test.ts +24 -93
  12. package/src/organization-model/__tests__/graph.test.ts +82 -894
  13. package/src/organization-model/__tests__/resolve.test.ts +59 -690
  14. package/src/organization-model/__tests__/schema.test.ts +83 -407
  15. package/src/organization-model/defaults.ts +276 -141
  16. package/src/organization-model/domains/features.ts +31 -22
  17. package/src/organization-model/foundation.ts +42 -54
  18. package/src/organization-model/graph/build.ts +42 -217
  19. package/src/organization-model/graph/index.ts +4 -4
  20. package/src/organization-model/graph/link.ts +10 -0
  21. package/src/organization-model/graph/schema.ts +21 -16
  22. package/src/organization-model/graph/types.ts +10 -10
  23. package/src/organization-model/helpers.ts +74 -0
  24. package/src/organization-model/index.ts +7 -7
  25. package/src/organization-model/organization-graph.mdx +89 -272
  26. package/src/organization-model/organization-model.mdx +149 -320
  27. package/src/organization-model/published.ts +15 -15
  28. package/src/organization-model/resolve.ts +8 -33
  29. package/src/organization-model/schema.ts +63 -205
  30. package/src/organization-model/types.ts +12 -11
  31. package/src/platform/registry/__tests__/command-view.test.ts +6 -5
  32. package/src/platform/registry/__tests__/resource-link.test.ts +30 -0
  33. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +15 -15
  34. package/src/platform/registry/command-view.ts +10 -12
  35. package/src/platform/registry/index.ts +13 -8
  36. package/src/platform/registry/resource-link.ts +32 -0
  37. package/src/platform/registry/resource-registry.ts +12 -10
  38. package/src/platform/registry/serialization.ts +56 -73
  39. package/src/platform/registry/serialized-types.ts +17 -12
  40. package/src/platform/registry/types.ts +14 -43
  41. package/src/reference/_generated/contracts.md +62 -148
  42. package/src/reference/glossary.md +71 -105
  43. package/src/test-utils/README.md +5 -10
  44. package/src/test-utils/entities.ts +108 -0
  45. package/src/test-utils/index.ts +2 -0
  46. package/src/test-utils/organization-model.ts +65 -0
  47. package/src/test-utils/published.ts +4 -2
  48. package/src/test-utils/test-utils.test.ts +49 -0
  49. package/src/platform/registry/domains.ts +0 -165
@@ -1,407 +1,83 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { DEFAULT_ORGANIZATION_MODEL_BRANDING } from '../domains/branding'
3
- import { DEFAULT_ORGANIZATION_MODEL_SALES } from '../domains/sales'
4
- import { DEFAULT_ORGANIZATION_MODEL_PROJECTS } from '../domains/projects'
5
- import { DEFAULT_ORGANIZATION_MODEL_PROSPECTING } from '../domains/prospecting'
6
- import { OrganizationModelSchema } from '../schema'
7
-
8
- // ---------------------------------------------------------------------------
9
- // Minimal valid fixture builders
10
- // ---------------------------------------------------------------------------
11
-
12
- function makeFeature(id: string, surfaceIds: string[] = [], resourceIds: string[] = []) {
13
- return {
14
- id,
15
- label: id,
16
- enabled: true,
17
- entityIds: [],
18
- surfaceIds,
19
- resourceIds,
20
- capabilityIds: []
21
- }
22
- }
23
-
24
- function makeSurface(id: string, featureIds: string[] = [], resourceIds: string[] = []) {
25
- return {
26
- id,
27
- label: id,
28
- path: `/${id}`,
29
- surfaceType: 'page' as const,
30
- featureIds,
31
- entityIds: [],
32
- resourceIds,
33
- capabilityIds: []
34
- }
35
- }
36
-
37
- function makeGroup(id: string, surfaceIds: string[] = []) {
38
- return { id, label: id, placement: 'primary' as const, surfaceIds }
39
- }
40
-
41
- function makeResourceMapping(id: string, resourceId: string, featureIds: string[] = [], surfaceIds: string[] = []) {
42
- return {
43
- id,
44
- label: id,
45
- resourceId,
46
- resourceType: 'workflow' as const,
47
- featureIds,
48
- entityIds: [],
49
- surfaceIds,
50
- capabilityIds: []
51
- }
52
- }
53
-
54
- /**
55
- * A minimal model that satisfies all base-schema field requirements.
56
- * The crm/leadGen/delivery fields use the official defaults so the schema
57
- * layer validates cleanly, leaving superRefine as the only concern.
58
- */
59
- function makeMinimalModel(
60
- navOverride: { defaultSurfaceId?: string; surfaces?: unknown[]; groups?: unknown[] } = {},
61
- extras: { features?: unknown[]; resourceMappings?: unknown[] } = {}
62
- ) {
63
- return {
64
- version: 1 as const,
65
- features: extras.features ?? [],
66
- branding: DEFAULT_ORGANIZATION_MODEL_BRANDING,
67
- navigation: {
68
- defaultSurfaceId: navOverride.defaultSurfaceId,
69
- surfaces: navOverride.surfaces ?? [],
70
- groups: navOverride.groups ?? []
71
- },
72
- sales: DEFAULT_ORGANIZATION_MODEL_SALES,
73
- prospecting: DEFAULT_ORGANIZATION_MODEL_PROSPECTING,
74
- projects: DEFAULT_ORGANIZATION_MODEL_PROJECTS,
75
- resourceMappings: extras.resourceMappings ?? []
76
- }
77
- }
78
-
79
- // ---------------------------------------------------------------------------
80
- // Helper: collect all Zod issue messages from a failed parse
81
- // ---------------------------------------------------------------------------
82
-
83
- function getIssueMessages(data: unknown): string[] {
84
- const result = OrganizationModelSchema.safeParse(data)
85
- if (result.success) return []
86
- return result.error.issues.map((i) => i.message)
87
- }
88
-
89
- // ---------------------------------------------------------------------------
90
- // Group 1: Bidirectional feature <-> surface refs
91
- // ---------------------------------------------------------------------------
92
-
93
- describe('bidirectional feature <-> surface refs', () => {
94
- it('passes when feature and surface correctly reference each other', () => {
95
- const model = makeMinimalModel(
96
- { surfaces: [makeSurface('crm.pipeline', ['crm'])], groups: [] },
97
- { features: [makeFeature('crm', ['crm.pipeline'])] }
98
- )
99
-
100
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
101
- })
102
-
103
- it('throws when feature references a surface that does not exist', () => {
104
- const model = makeMinimalModel(
105
- { surfaces: [], groups: [] },
106
- { features: [makeFeature('crm', ['nonexistent-surface'])] }
107
- )
108
-
109
- const messages = getIssueMessages(model)
110
- expect(messages.some((m) => m.includes('references unknown surface'))).toBe(true)
111
- })
112
-
113
- it('throws when feature references a surface that does not include the feature', () => {
114
- // Surface exists but its featureIds does not contain 'crm'
115
- const model = makeMinimalModel(
116
- { surfaces: [makeSurface('crm.pipeline', [] /* featureIds omits 'crm' */)], groups: [] },
117
- { features: [makeFeature('crm', ['crm.pipeline'])] }
118
- )
119
-
120
- const messages = getIssueMessages(model)
121
- expect(messages.some((m) => m.includes('does not include feature'))).toBe(true)
122
- })
123
-
124
- it('throws when surface references a feature that does not exist', () => {
125
- const model = makeMinimalModel(
126
- { surfaces: [makeSurface('crm.pipeline', ['nonexistent-feature'])], groups: [] },
127
- { features: [] }
128
- )
129
-
130
- const messages = getIssueMessages(model)
131
- expect(messages.some((m) => m.includes('references unknown feature'))).toBe(true)
132
- })
133
-
134
- it('throws when surface references a feature that does not include the surface', () => {
135
- // Feature exists but its surfaceIds does not contain 'crm.pipeline'
136
- const model = makeMinimalModel(
137
- { surfaces: [makeSurface('crm.pipeline', ['crm'])], groups: [] },
138
- { features: [makeFeature('crm', [] /* surfaceIds omits 'crm.pipeline' */)] }
139
- )
140
-
141
- const messages = getIssueMessages(model)
142
- expect(messages.some((m) => m.includes('does not include surface'))).toBe(true)
143
- })
144
- })
145
-
146
- // ---------------------------------------------------------------------------
147
- // Group 2: Duplicate ID detection
148
- // ---------------------------------------------------------------------------
149
-
150
- describe('duplicate ID detection', () => {
151
- it('throws on duplicate feature IDs', () => {
152
- const model = makeMinimalModel({ surfaces: [], groups: [] }, { features: [makeFeature('crm'), makeFeature('crm')] })
153
-
154
- const messages = getIssueMessages(model)
155
- expect(messages.some((m) => m.includes('Feature id "crm" must be unique'))).toBe(true)
156
- })
157
-
158
- it('throws on duplicate surface IDs', () => {
159
- const model = makeMinimalModel({
160
- surfaces: [makeSurface('home'), makeSurface('home')],
161
- groups: []
162
- })
163
-
164
- const messages = getIssueMessages(model)
165
- expect(messages.some((m) => m.includes('Surface id "home" must be unique'))).toBe(true)
166
- })
167
-
168
- it('throws on duplicate navigation group IDs', () => {
169
- const model = makeMinimalModel({
170
- surfaces: [],
171
- groups: [makeGroup('primary'), makeGroup('primary')]
172
- })
173
-
174
- const messages = getIssueMessages(model)
175
- expect(messages.some((m) => m.includes('Navigation group id "primary" must be unique'))).toBe(true)
176
- })
177
-
178
- it('throws on duplicate resource mapping IDs', () => {
179
- const model = makeMinimalModel(
180
- { surfaces: [], groups: [] },
181
- { resourceMappings: [makeResourceMapping('rm-1', 'res-a'), makeResourceMapping('rm-1', 'res-b')] }
182
- )
183
-
184
- const messages = getIssueMessages(model)
185
- expect(messages.some((m) => m.includes('Resource mapping id "rm-1" must be unique'))).toBe(true)
186
- })
187
-
188
- it('throws on duplicate resource mapping resourceIds', () => {
189
- const model = makeMinimalModel(
190
- { surfaces: [], groups: [] },
191
- {
192
- resourceMappings: [
193
- makeResourceMapping('rm-1', 'shared-resource'),
194
- makeResourceMapping('rm-2', 'shared-resource')
195
- ]
196
- }
197
- )
198
-
199
- const messages = getIssueMessages(model)
200
- expect(messages.some((m) => m.includes('resourceId "shared-resource" must be unique'))).toBe(true)
201
- })
202
-
203
- it('passes when all IDs are unique across all collections', () => {
204
- const model = makeMinimalModel(
205
- {
206
- surfaces: [makeSurface('surf-1'), makeSurface('surf-2')],
207
- groups: [makeGroup('grp-1'), makeGroup('grp-2')]
208
- },
209
- {
210
- features: [makeFeature('feat-a'), makeFeature('feat-b')],
211
- resourceMappings: [makeResourceMapping('rm-1', 'res-x'), makeResourceMapping('rm-2', 'res-y')]
212
- }
213
- )
214
-
215
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
216
- })
217
- })
218
-
219
- // ---------------------------------------------------------------------------
220
- // Group 3: defaultSurfaceId correctness
221
- // ---------------------------------------------------------------------------
222
-
223
- describe('defaultSurfaceId correctness', () => {
224
- it('passes when defaultSurfaceId points at a declared surface', () => {
225
- const model = makeMinimalModel(
226
- {
227
- defaultSurfaceId: 'crm.pipeline',
228
- surfaces: [makeSurface('crm.pipeline', ['crm'])],
229
- groups: []
230
- },
231
- { features: [makeFeature('crm', ['crm.pipeline'])] }
232
- )
233
-
234
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
235
- })
236
-
237
- it('throws when defaultSurfaceId references a surface that does not exist', () => {
238
- const model = makeMinimalModel({
239
- defaultSurfaceId: 'nonexistent',
240
- surfaces: [],
241
- groups: []
242
- })
243
-
244
- const messages = getIssueMessages(model)
245
- expect(messages.some((m) => m.includes('must reference a declared navigation surface'))).toBe(true)
246
- })
247
-
248
- it('passes when defaultSurfaceId is absent (undefined)', () => {
249
- // NOTE: The falsy guard in schema.ts (line 69) skips the check entirely when
250
- // defaultSurfaceId is undefined. This is current behavior — documented here.
251
- const model = makeMinimalModel({ surfaces: [], groups: [] })
252
-
253
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
254
- })
255
- })
256
-
257
- // ---------------------------------------------------------------------------
258
- // Group 4: Resource-mapping feature <-> surface cross-refs
259
- // ---------------------------------------------------------------------------
260
-
261
- describe('resource-mapping feature <-> surface cross-refs', () => {
262
- it('passes with a fully consistent resource mapping', () => {
263
- const model = makeMinimalModel(
264
- { surfaces: [makeSurface('crm.pipeline', ['crm'], ['workflow-a'])], groups: [] },
265
- {
266
- features: [makeFeature('crm', ['crm.pipeline'], ['workflow-a'])],
267
- resourceMappings: [makeResourceMapping('rm-1', 'workflow-a', ['crm'], ['crm.pipeline'])]
268
- }
269
- )
270
-
271
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
272
- })
273
-
274
- it('throws when resource mapping references a feature that does not exist', () => {
275
- const model = makeMinimalModel(
276
- { surfaces: [], groups: [] },
277
- { resourceMappings: [makeResourceMapping('rm-1', 'res-a', ['nonexistent-feature'])] }
278
- )
279
-
280
- const messages = getIssueMessages(model)
281
- expect(messages.some((m) => m.includes('references unknown feature'))).toBe(true)
282
- })
283
-
284
- it('throws when resource mapping references a surface that does not exist', () => {
285
- const model = makeMinimalModel(
286
- { surfaces: [], groups: [] },
287
- { resourceMappings: [makeResourceMapping('rm-1', 'res-a', [], ['nonexistent-surface'])] }
288
- )
289
-
290
- const messages = getIssueMessages(model)
291
- expect(messages.some((m) => m.includes('references unknown surface'))).toBe(true)
292
- })
293
-
294
- it('throws when feature resourceId ref exists but mapping does not back-reference the feature', () => {
295
- // Resource mapping exists for 'workflow-a', feature lists it, but mapping.featureIds is empty
296
- const model = makeMinimalModel(
297
- { surfaces: [], groups: [] },
298
- {
299
- features: [makeFeature('crm', [], ['workflow-a'])],
300
- resourceMappings: [makeResourceMapping('rm-1', 'workflow-a', [] /* missing 'crm' */)]
301
- }
302
- )
303
-
304
- const messages = getIssueMessages(model)
305
- // Feature side: "does not include resource"; ResourceMapping side: the feature is missing
306
- expect(
307
- messages.some((m) => m.includes('does not include resource') || m.includes('does not include feature'))
308
- ).toBe(true)
309
- })
310
-
311
- it('throws when surface resourceId ref exists but mapping does not back-reference the surface', () => {
312
- // Resource mapping exists for 'workflow-b', surface lists it, but mapping.surfaceIds is empty
313
- const model = makeMinimalModel(
314
- { surfaces: [makeSurface('home', [], ['workflow-b'])], groups: [] },
315
- { resourceMappings: [makeResourceMapping('rm-2', 'workflow-b', [], [] /* missing 'home' */)] }
316
- )
317
-
318
- const messages = getIssueMessages(model)
319
- expect(
320
- messages.some((m) => m.includes('does not include resource') || m.includes('does not include surface'))
321
- ).toBe(true)
322
- })
323
-
324
- it('throws when feature references a resourceId that has no matching resource mapping', () => {
325
- const model = makeMinimalModel(
326
- { surfaces: [], groups: [] },
327
- {
328
- features: [makeFeature('crm', [], ['unknown-resource'])],
329
- resourceMappings: []
330
- }
331
- )
332
-
333
- const messages = getIssueMessages(model)
334
- expect(messages.some((m) => m.includes('references unknown resource'))).toBe(true)
335
- })
336
- })
337
-
338
- // ---------------------------------------------------------------------------
339
- // Group 5: Null / undefined behavior in ref fields
340
- // ---------------------------------------------------------------------------
341
-
342
- describe('null/undefined behavior in ref fields', () => {
343
- it('treats missing surfaceIds as empty array via Zod default — no superRefine errors', () => {
344
- // ReferenceIdsSchema defaults to []; omitting surfaceIds is safe — nothing to iterate
345
- const model = makeMinimalModel(
346
- { surfaces: [], groups: [] },
347
- {
348
- features: [
349
- {
350
- id: 'crm',
351
- label: 'CRM',
352
- enabled: true,
353
- entityIds: [],
354
- // surfaceIds intentionally omitted — Zod fills in []
355
- resourceIds: [],
356
- capabilityIds: []
357
- }
358
- ]
359
- }
360
- )
361
-
362
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
363
- })
364
-
365
- it('treats missing featureIds on a surface as empty array — no superRefine errors', () => {
366
- const model = makeMinimalModel({
367
- surfaces: [
368
- {
369
- id: 'home',
370
- label: 'Home',
371
- path: '/home',
372
- surfaceType: 'page' as const,
373
- // featureIds intentionally omitted — Zod fills in []
374
- entityIds: [],
375
- resourceIds: [],
376
- capabilityIds: []
377
- }
378
- ],
379
- groups: []
380
- })
381
-
382
- expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
383
- })
384
-
385
- it('rejects explicit null for surfaceIds — Zod type error before superRefine runs', () => {
386
- // null is not assignable to an array; the base schema rejects it before superRefine executes
387
- const model = makeMinimalModel(
388
- { surfaces: [], groups: [] },
389
- {
390
- features: [
391
- {
392
- id: 'crm',
393
- label: 'CRM',
394
- enabled: true,
395
- entityIds: [],
396
- surfaceIds: null,
397
- resourceIds: [],
398
- capabilityIds: []
399
- }
400
- ]
401
- }
402
- )
403
-
404
- const result = OrganizationModelSchema.safeParse(model)
405
- expect(result.success).toBe(false)
406
- })
407
- })
1
+ import { describe, expect, it } from 'vitest'
2
+ import { DEFAULT_ORGANIZATION_MODEL_BRANDING } from '../domains/branding'
3
+ import { DEFAULT_ORGANIZATION_MODEL_SALES } from '../domains/sales'
4
+ import { DEFAULT_ORGANIZATION_MODEL_PROJECTS } from '../domains/projects'
5
+ import { DEFAULT_ORGANIZATION_MODEL_PROSPECTING } from '../domains/prospecting'
6
+ import { OrganizationModelSchema } from '../schema'
7
+
8
+ function makeFeature(id: string, path = `/${id.replaceAll('.', '/')}`) {
9
+ return {
10
+ id,
11
+ label: id,
12
+ enabled: true,
13
+ path
14
+ }
15
+ }
16
+
17
+ function makeMinimalModel(features: unknown[] = []) {
18
+ return {
19
+ version: 1 as const,
20
+ features,
21
+ branding: DEFAULT_ORGANIZATION_MODEL_BRANDING,
22
+ sales: DEFAULT_ORGANIZATION_MODEL_SALES,
23
+ prospecting: DEFAULT_ORGANIZATION_MODEL_PROSPECTING,
24
+ projects: DEFAULT_ORGANIZATION_MODEL_PROJECTS
25
+ }
26
+ }
27
+
28
+ function getIssueMessages(data: unknown): string[] {
29
+ const result = OrganizationModelSchema.safeParse(data)
30
+ if (result.success) return []
31
+ return result.error.issues.map((issue) => issue.message)
32
+ }
33
+
34
+ describe('flat feature tree validation', () => {
35
+ it('passes with a flat list that has declared ancestors', () => {
36
+ const model = makeMinimalModel([
37
+ { id: 'sales', label: 'Sales', enabled: true },
38
+ makeFeature('sales.crm', '/sales/crm/pipeline'),
39
+ makeFeature('sales.lead-gen', '/lead-gen/lists')
40
+ ])
41
+
42
+ expect(() => OrganizationModelSchema.parse(model)).not.toThrow()
43
+ })
44
+
45
+ it('rejects duplicate feature ids', () => {
46
+ const messages = getIssueMessages(makeMinimalModel([makeFeature('sales'), makeFeature('sales')]))
47
+
48
+ expect(messages.some((message) => message.includes('Feature id "sales" must be unique'))).toBe(true)
49
+ })
50
+
51
+ it('rejects a dotted child when its immediate parent is missing', () => {
52
+ const messages = getIssueMessages(makeMinimalModel([makeFeature('sales.crm.pipeline')]))
53
+
54
+ expect(messages.some((message) => message.includes('unknown parent "sales.crm"'))).toBe(true)
55
+ })
56
+
57
+ it('allows a leaf without a path so resolvers can derive a default path', () => {
58
+ const result = OrganizationModelSchema.safeParse(makeMinimalModel([{ id: 'sales', label: 'Sales', enabled: true }]))
59
+
60
+ expect(result.success).toBe(true)
61
+ })
62
+
63
+ it('rejects an enabled container with no enabled descendants', () => {
64
+ const messages = getIssueMessages(
65
+ makeMinimalModel([
66
+ { id: 'sales', label: 'Sales', enabled: true },
67
+ { id: 'sales.crm', label: 'CRM', enabled: false, path: '/sales/crm/pipeline' }
68
+ ])
69
+ )
70
+
71
+ expect(messages.some((message) => message.includes('has no enabled descendants'))).toBe(true)
72
+ })
73
+
74
+ it('keeps legacy navigation inert during the release train', () => {
75
+ const model = OrganizationModelSchema.parse(
76
+ makeMinimalModel([makeFeature('dashboard', '/')])
77
+ )
78
+
79
+ expect(model.navigation.surfaces).toEqual([])
80
+ expect(model.navigation.groups).toEqual([])
81
+ expect('resourceMappings' in model).toBe(false)
82
+ })
83
+ })