@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
@@ -0,0 +1,108 @@
1
+ import type { z } from 'zod'
2
+ import {
3
+ BaseCompanySchema,
4
+ BaseContactSchema,
5
+ BaseDealSchema,
6
+ BaseMilestoneSchema,
7
+ BaseProjectSchema,
8
+ BaseTaskSchema
9
+ } from '../business/base-entities'
10
+
11
+ type BaseProjectFixture = z.infer<typeof BaseProjectSchema>
12
+ type BaseDealFixture = z.infer<typeof BaseDealSchema>
13
+ type BaseCompanyFixture = z.infer<typeof BaseCompanySchema>
14
+ type BaseContactFixture = z.infer<typeof BaseContactSchema>
15
+ type BaseMilestoneFixture = z.infer<typeof BaseMilestoneSchema>
16
+ type BaseTaskFixture = z.infer<typeof BaseTaskSchema>
17
+
18
+ const DEFAULT_ORGANIZATION_ID = '00000000-0000-0000-0000-000000000010'
19
+ const DEFAULT_PROJECT_ID = '00000000-0000-0000-0000-000000000100'
20
+ const DEFAULT_TIMESTAMP = '2025-01-01T00:00:00Z'
21
+
22
+ export function makeProject(overrides: Partial<BaseProjectFixture> = {}): BaseProjectFixture {
23
+ return BaseProjectSchema.parse({
24
+ id: DEFAULT_PROJECT_ID,
25
+ organizationId: DEFAULT_ORGANIZATION_ID,
26
+ name: 'Test Project',
27
+ kind: 'client-delivery',
28
+ status: 'active',
29
+ description: 'A test project',
30
+ metadata: {},
31
+ createdAt: DEFAULT_TIMESTAMP,
32
+ updatedAt: DEFAULT_TIMESTAMP,
33
+ ...overrides
34
+ })
35
+ }
36
+
37
+ export function makeDeal(overrides: Partial<BaseDealFixture> = {}): BaseDealFixture {
38
+ return BaseDealSchema.parse({
39
+ id: '00000000-0000-0000-0000-000000000200',
40
+ organizationId: DEFAULT_ORGANIZATION_ID,
41
+ contactEmail: 'buyer@test.com',
42
+ stage: 'qualified',
43
+ metadata: {},
44
+ createdAt: DEFAULT_TIMESTAMP,
45
+ updatedAt: DEFAULT_TIMESTAMP,
46
+ ...overrides
47
+ })
48
+ }
49
+
50
+ export function makeCompany(overrides: Partial<BaseCompanyFixture> = {}): BaseCompanyFixture {
51
+ return BaseCompanySchema.parse({
52
+ id: '00000000-0000-0000-0000-000000000300',
53
+ organizationId: DEFAULT_ORGANIZATION_ID,
54
+ name: 'Test Company',
55
+ domain: 'test.example',
56
+ status: 'active',
57
+ metadata: {},
58
+ createdAt: DEFAULT_TIMESTAMP,
59
+ updatedAt: DEFAULT_TIMESTAMP,
60
+ ...overrides
61
+ })
62
+ }
63
+
64
+ export function makeContact(overrides: Partial<BaseContactFixture> = {}): BaseContactFixture {
65
+ return BaseContactSchema.parse({
66
+ id: '00000000-0000-0000-0000-000000000400',
67
+ organizationId: DEFAULT_ORGANIZATION_ID,
68
+ email: 'contact@test.com',
69
+ firstName: 'Test',
70
+ lastName: 'Contact',
71
+ status: 'active',
72
+ metadata: {},
73
+ createdAt: DEFAULT_TIMESTAMP,
74
+ updatedAt: DEFAULT_TIMESTAMP,
75
+ ...overrides
76
+ })
77
+ }
78
+
79
+ export function makeMilestone(overrides: Partial<BaseMilestoneFixture> = {}): BaseMilestoneFixture {
80
+ return BaseMilestoneSchema.parse({
81
+ id: '00000000-0000-0000-0000-000000000500',
82
+ organizationId: DEFAULT_ORGANIZATION_ID,
83
+ projectId: DEFAULT_PROJECT_ID,
84
+ name: 'Test Milestone',
85
+ status: 'not-started',
86
+ description: 'A test milestone',
87
+ metadata: {},
88
+ createdAt: DEFAULT_TIMESTAMP,
89
+ updatedAt: DEFAULT_TIMESTAMP,
90
+ ...overrides
91
+ })
92
+ }
93
+
94
+ export function makeTask(overrides: Partial<BaseTaskFixture> = {}): BaseTaskFixture {
95
+ return BaseTaskSchema.parse({
96
+ id: '00000000-0000-0000-0000-000000000600',
97
+ organizationId: DEFAULT_ORGANIZATION_ID,
98
+ projectId: DEFAULT_PROJECT_ID,
99
+ name: 'Test Task',
100
+ status: 'todo',
101
+ type: 'general',
102
+ description: 'A test task',
103
+ metadata: {},
104
+ createdAt: DEFAULT_TIMESTAMP,
105
+ updatedAt: DEFAULT_TIMESTAMP,
106
+ ...overrides
107
+ })
108
+ }
@@ -8,3 +8,5 @@ export * from './browser-mocks'
8
8
  // publishConfig.exports keeps these out of the public @elevasis/core package.
9
9
  export * from './fixtures'
10
10
  export * from './mocks'
11
+ export * from './entities'
12
+ export * from './organization-model'
@@ -0,0 +1,65 @@
1
+ import type { DeepPartial, OrganizationModel } from '../organization-model/published'
2
+ import { OrganizationModelSchema, resolveOrganizationModel } from '../organization-model/published'
3
+ import type { SupabaseUserProfile } from '../supabase'
4
+ import { createTestUser } from './fixtures'
5
+
6
+ export interface TestInitializationError {
7
+ layer: 'auth' | 'profile' | 'organization'
8
+ message: string
9
+ originalError?: Error
10
+ }
11
+
12
+ export interface TestInitializationState {
13
+ userReady: boolean
14
+ organizationReady: boolean
15
+ allReady: boolean
16
+ isInitializing: boolean
17
+ error: TestInitializationError | null
18
+ retry: () => void
19
+ profile: SupabaseUserProfile | null
20
+ }
21
+
22
+ export type TestInitializationStateOverrides = Partial<
23
+ Omit<TestInitializationState, 'error' | 'profile' | 'retry'>
24
+ > & {
25
+ error?: TestInitializationError | null
26
+ profile?: Partial<SupabaseUserProfile> | SupabaseUserProfile | null
27
+ retry?: () => void
28
+ }
29
+
30
+ export function makeOrganizationModel(
31
+ overrides?: DeepPartial<OrganizationModel>
32
+ ): OrganizationModel {
33
+ return OrganizationModelSchema.parse(resolveOrganizationModel(overrides))
34
+ }
35
+
36
+ export function makeUserProfile(
37
+ overrides: Partial<SupabaseUserProfile> = {}
38
+ ): SupabaseUserProfile {
39
+ return createTestUser(overrides)
40
+ }
41
+
42
+ export function makeInitializationState(
43
+ overrides: TestInitializationStateOverrides = {}
44
+ ): TestInitializationState {
45
+ const defaultState: TestInitializationState = {
46
+ userReady: true,
47
+ organizationReady: true,
48
+ allReady: true,
49
+ isInitializing: false,
50
+ error: null,
51
+ retry: () => undefined,
52
+ profile: makeUserProfile()
53
+ }
54
+
55
+ return {
56
+ ...defaultState,
57
+ ...overrides,
58
+ profile:
59
+ overrides.profile === undefined
60
+ ? defaultState.profile
61
+ : overrides.profile === null
62
+ ? null
63
+ : makeUserProfile(overrides.profile)
64
+ }
65
+ }
@@ -1,4 +1,6 @@
1
- // Published test utilities are intentionally narrow.
2
- // Internal fixtures and Vitest-heavy mocks remain monorepo-only.
3
1
  export * from './rls'
4
2
  export * from './browser-mocks'
3
+ export * from './fixtures'
4
+ export * from './mocks'
5
+ export * from './entities'
6
+ export * from './organization-model'
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { BaseProjectSchema, BaseTaskSchema } from '../business/base-entities'
3
+ import { DEFAULT_ORGANIZATION_MODEL } from '../organization-model'
4
+ import {
5
+ makeInitializationState,
6
+ makeOrganizationModel,
7
+ makeProject,
8
+ makeTask,
9
+ makeUserProfile,
10
+ TEST_ORGS,
11
+ TEST_USERS
12
+ } from './published'
13
+
14
+ describe('published test-utils factories', () => {
15
+ it('creates schema-validated base entities with overrides', () => {
16
+ const project = makeProject({ name: 'Custom Project', metadata: { source: 'test' } })
17
+ const task = makeTask({ projectId: project.id, status: 'done' })
18
+
19
+ expect(BaseProjectSchema.parse(project)).toMatchObject({
20
+ name: 'Custom Project',
21
+ metadata: { source: 'test' }
22
+ })
23
+ expect(BaseTaskSchema.parse(task)).toMatchObject({
24
+ projectId: project.id,
25
+ status: 'done'
26
+ })
27
+ })
28
+
29
+ it('creates organization model and initialization fixtures', () => {
30
+ const model = makeOrganizationModel({
31
+ branding: { organizationName: 'Test Brand' },
32
+ features: DEFAULT_ORGANIZATION_MODEL.features.map((feature) =>
33
+ feature.id === 'seo' ? { ...feature, enabled: true } : feature
34
+ )
35
+ })
36
+ const profile = makeUserProfile({ id: TEST_USERS.admin.id, email: TEST_USERS.admin.email })
37
+ const state = makeInitializationState({ profile, organizationReady: false, allReady: false })
38
+
39
+ expect(model.branding.organizationName).toBe('Test Brand')
40
+ expect(model.features.find((feature) => feature.id === 'seo')?.enabled).toBe(true)
41
+ expect(state.profile?.email).toBe(TEST_USERS.admin.email)
42
+ expect(state.organizationReady).toBe(false)
43
+ })
44
+
45
+ it('promotes existing fixture surface through the public barrel', () => {
46
+ expect(TEST_USERS.admin.email).toBe('admin@test.com')
47
+ expect(TEST_ORGS.acme.name).toBe('Acme Corp')
48
+ })
49
+ })
@@ -1,165 +0,0 @@
1
- /**
2
- * Standard Domain Definitions
3
- * Centralized domain constants and definitions for all organization resources.
4
- */
5
-
6
- import type { DomainDefinition } from './types'
7
-
8
- // ============================================================================
9
- // Standard Domain IDs
10
- // ============================================================================
11
-
12
- export const DOMAINS = {
13
- // Business domains
14
- INBOUND_PIPELINE: 'inbound-pipeline',
15
- LEAD_GEN_PIPELINE: 'lead-gen-pipeline',
16
- SUPPORT: 'support',
17
- CLIENT_SUPPORT: 'client-support',
18
- DELIVERY: 'delivery',
19
- OPERATIONS: 'operations',
20
- FINANCE: 'finance',
21
- EXECUTIVE: 'executive',
22
- INSTANTLY: 'instantly',
23
-
24
- // Technical domains
25
- TESTING: 'testing',
26
- INTERNAL: 'internal',
27
- INTEGRATION: 'integration',
28
- UTILITY: 'utility',
29
- DIAGNOSTIC: 'diagnostic'
30
- } as const
31
-
32
- /**
33
- * ResourceDomain - Strongly typed domain identifier
34
- * Use this type for all domain references to ensure compile-time validation.
35
- */
36
- export type ResourceDomain = (typeof DOMAINS)[keyof typeof DOMAINS]
37
-
38
- // ============================================================================
39
- // Domain Definitions
40
- // ============================================================================
41
-
42
- export const INBOUND_PIPELINE_DOMAIN: DomainDefinition = {
43
- id: DOMAINS.INBOUND_PIPELINE,
44
- name: 'Inbound Pipeline',
45
- description: 'End-to-end inbound client acquisition from first reply to onboarding',
46
- color: 'blue'
47
- }
48
-
49
- export const LEAD_GEN_PIPELINE_DOMAIN: DomainDefinition = {
50
- id: DOMAINS.LEAD_GEN_PIPELINE,
51
- name: 'Lead Gen Pipeline',
52
- description: 'Lead scraping, enrichment, qualification, and personalization',
53
- color: 'cyan'
54
- }
55
-
56
- export const SUPPORT_DOMAIN: DomainDefinition = {
57
- id: DOMAINS.SUPPORT,
58
- name: 'Customer Support',
59
- description: 'Ticket triage, knowledge base, escalations',
60
- color: 'green'
61
- }
62
-
63
- export const CLIENT_SUPPORT_DOMAIN: DomainDefinition = {
64
- id: DOMAINS.CLIENT_SUPPORT,
65
- name: 'Client Support',
66
- description: 'Client change requests, bug reports, and feature requests',
67
- color: 'teal'
68
- }
69
-
70
- export const DELIVERY_DOMAIN: DomainDefinition = {
71
- id: DOMAINS.DELIVERY,
72
- name: 'Client Delivery',
73
- description: 'Project execution and milestone tracking',
74
- color: 'orange'
75
- }
76
-
77
- export const OPERATIONS_DOMAIN: DomainDefinition = {
78
- id: DOMAINS.OPERATIONS,
79
- name: 'Operations',
80
- description: 'Internal business operations and administration',
81
- color: 'violet'
82
- }
83
-
84
- export const FINANCE_DOMAIN: DomainDefinition = {
85
- id: DOMAINS.FINANCE,
86
- name: 'Finance',
87
- description: 'Billing, invoicing, and financial operations',
88
- color: 'pink'
89
- }
90
-
91
- export const EXECUTIVE_DOMAIN: DomainDefinition = {
92
- id: DOMAINS.EXECUTIVE,
93
- name: 'Executive Operations',
94
- description: 'High-level business orchestration and decision-making',
95
- color: 'indigo'
96
- }
97
-
98
- export const TESTING_DOMAIN: DomainDefinition = {
99
- id: DOMAINS.TESTING,
100
- name: 'Testing',
101
- description: 'Test resources and development workflows',
102
- color: 'gray'
103
- }
104
-
105
- export const INTERNAL_DOMAIN: DomainDefinition = {
106
- id: DOMAINS.INTERNAL,
107
- name: 'Internal',
108
- description: 'Internal platform resources',
109
- color: 'dark'
110
- }
111
-
112
- export const INTEGRATION_DOMAIN: DomainDefinition = {
113
- id: DOMAINS.INTEGRATION,
114
- name: 'Integration',
115
- description: 'External service integrations',
116
- color: 'teal'
117
- }
118
-
119
- export const INSTANTLY_DOMAIN: DomainDefinition = {
120
- id: DOMAINS.INSTANTLY,
121
- name: 'Instantly Toolkit',
122
- description: 'Instantly campaign creation, analytics, and optimization',
123
- color: 'lime'
124
- }
125
-
126
- export const UTILITY_DOMAIN: DomainDefinition = {
127
- id: DOMAINS.UTILITY,
128
- name: 'Utility',
129
- description: 'Utility workflows for maintenance and diagnostics',
130
- color: 'grape'
131
- }
132
-
133
- export const DIAGNOSTIC_DOMAIN: DomainDefinition = {
134
- id: DOMAINS.DIAGNOSTIC,
135
- name: 'Diagnostic',
136
- description: 'Diagnostic workflows for testing integrations and services',
137
- color: 'yellow'
138
- }
139
-
140
- /**
141
- * Domain lookup map for O(1) access during serialization
142
- */
143
- export const DOMAIN_MAP: Record<ResourceDomain, DomainDefinition> = {
144
- [DOMAINS.INBOUND_PIPELINE]: INBOUND_PIPELINE_DOMAIN,
145
- [DOMAINS.LEAD_GEN_PIPELINE]: LEAD_GEN_PIPELINE_DOMAIN,
146
- [DOMAINS.SUPPORT]: SUPPORT_DOMAIN,
147
- [DOMAINS.CLIENT_SUPPORT]: CLIENT_SUPPORT_DOMAIN,
148
- [DOMAINS.DELIVERY]: DELIVERY_DOMAIN,
149
- [DOMAINS.OPERATIONS]: OPERATIONS_DOMAIN,
150
- [DOMAINS.FINANCE]: FINANCE_DOMAIN,
151
- [DOMAINS.EXECUTIVE]: EXECUTIVE_DOMAIN,
152
- [DOMAINS.TESTING]: TESTING_DOMAIN,
153
- [DOMAINS.INTERNAL]: INTERNAL_DOMAIN,
154
- [DOMAINS.INSTANTLY]: INSTANTLY_DOMAIN,
155
- [DOMAINS.INTEGRATION]: INTEGRATION_DOMAIN,
156
- [DOMAINS.UTILITY]: UTILITY_DOMAIN,
157
- [DOMAINS.DIAGNOSTIC]: DIAGNOSTIC_DOMAIN
158
- }
159
-
160
- /**
161
- * Get domain definition by ID
162
- */
163
- export function getDomainDefinition(id: ResourceDomain): DomainDefinition {
164
- return DOMAIN_MAP[id]
165
- }