@elevasis/sdk 1.4.0 → 1.5.1

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 (31) hide show
  1. package/dist/cli.cjs +100 -12
  2. package/dist/index.d.ts +1464 -749
  3. package/dist/index.js +74 -7
  4. package/dist/types/worker/adapters/crm.d.ts +20 -0
  5. package/dist/types/worker/adapters/index.d.ts +2 -0
  6. package/dist/types/worker/adapters/projects.d.ts +20 -0
  7. package/dist/worker/index.js +41 -1
  8. package/package.json +2 -2
  9. package/reference/_navigation.md +24 -0
  10. package/reference/deployment/provided-features.mdx +64 -25
  11. package/reference/framework/index.mdx +2 -2
  12. package/reference/framework/project-structure.mdx +10 -8
  13. package/reference/index.mdx +3 -3
  14. package/reference/packages/core/src/organization-model/README.md +19 -4
  15. package/reference/resources/patterns.mdx +54 -8
  16. package/reference/scaffold/core/organization-graph.mdx +262 -0
  17. package/reference/scaffold/core/organization-model.mdx +257 -0
  18. package/reference/scaffold/index.mdx +59 -0
  19. package/reference/scaffold/operations/workflow-recipes.md +419 -0
  20. package/reference/scaffold/recipes/add-a-feature.md +142 -0
  21. package/reference/scaffold/recipes/add-a-resource.md +163 -0
  22. package/reference/scaffold/recipes/gate-by-feature-or-admin.md +152 -0
  23. package/reference/scaffold/recipes/index.md +32 -0
  24. package/reference/scaffold/reference/contracts.md +1044 -0
  25. package/reference/scaffold/reference/feature-registry.md +30 -0
  26. package/reference/scaffold/reference/glossary.md +88 -0
  27. package/reference/scaffold/ui/composition-extensibility.mdx +216 -0
  28. package/reference/scaffold/ui/customization.md +239 -0
  29. package/reference/scaffold/ui/feature-flags-and-gating.md +265 -0
  30. package/reference/scaffold/ui/feature-shell.mdx +241 -0
  31. package/reference/scaffold/ui/recipes.md +418 -0
@@ -0,0 +1,163 @@
1
+ ---
2
+ title: Add a Resource
3
+ description: End-to-end walkthrough for adding a new workflow or agent to the deployment spec, declaring relationships, and verifying in the resource inventory.
4
+ ---
5
+
6
+ # Add a Resource
7
+
8
+ End-to-end: add a new workflow or agent to `operations/` and verify it in the platform inventory. Steps are sequential.
9
+
10
+ See [glossary.md](../reference/glossary.md) under **Resource**, **DeploymentSpec**, and **Topology**. See [contracts.md](../reference/contracts.md) for `OrganizationModel` and `OrganizationModelResourceMapping` shapes.
11
+
12
+ ---
13
+
14
+ ## 1. Author the resource
15
+
16
+ Create `operations/src/<name>/index.ts`. Follow the anatomy from [workflow-recipes.md](../operations/workflow-recipes.md) recipe 1 for the full `WorkflowDefinition` shape.
17
+
18
+ ```ts
19
+ import type { WorkflowDefinition } from '@elevasis/sdk'
20
+ import { StepType } from '@elevasis/sdk'
21
+ import { myInputSchema, myOutputSchema } from '@foundation/types'
22
+
23
+ export const myWorkflow: WorkflowDefinition = {
24
+ config: {
25
+ resourceId: 'my-workflow',
26
+ name: 'My Workflow',
27
+ type: 'workflow',
28
+ version: '1.0.0',
29
+ status: 'dev'
30
+ },
31
+ contract: {
32
+ inputSchema: myInputSchema,
33
+ outputSchema: myOutputSchema
34
+ },
35
+ steps: {
36
+ run: {
37
+ id: 'run',
38
+ name: 'Run',
39
+ handler: async (rawInput, context) => {
40
+ context.logger.info('[run] starting')
41
+ // ...
42
+ return { result: 'done' }
43
+ },
44
+ inputSchema: myInputSchema,
45
+ outputSchema: myOutputSchema,
46
+ next: null
47
+ }
48
+ },
49
+ entryPoint: 'run'
50
+ }
51
+ ```
52
+
53
+ Define input/output schemas in `foundations/types/index.ts`, not inline. Both runtimes import from `@foundation/types`. See [workflow-recipes.md](../operations/workflow-recipes.md) for Zod schema conventions and adapter usage (`llm`, `storage`, `scheduler`, `notifications` from `@elevasis/sdk/worker`).
54
+
55
+ ---
56
+
57
+ ## 2. Register in the DeploymentSpec
58
+
59
+ Create an exports barrel at `operations/src/<name>/exports.ts`:
60
+
61
+ ```ts
62
+ import { myWorkflow } from './index.js'
63
+ import type { WorkflowDefinition } from '@elevasis/sdk'
64
+
65
+ export const workflows: WorkflowDefinition[] = [myWorkflow]
66
+ export const agents: never[] = []
67
+ ```
68
+
69
+ Then spread into the top-level spec at `operations/src/index.ts`:
70
+
71
+ ```ts
72
+ import * as myFeature from './my-feature/exports.js'
73
+
74
+ const org: DeploymentSpec = {
75
+ version: '0.1.0',
76
+ workflows: [...existing.workflows, ...myFeature.workflows],
77
+ agents: [...existing.agents, ...myFeature.agents]
78
+ }
79
+ ```
80
+
81
+ Use `.js` extensions in imports even though source is TypeScript -- required for ESM interoperability.
82
+
83
+ ---
84
+
85
+ ## 3. (Optional) Declare relationships
86
+
87
+ If the resource triggers another resource, uses a human checkpoint, or depends on an integration, declare those relationships on the `DeploymentSpec`. See [glossary.md](../reference/glossary.md) under **Topology** for the three edge types (`triggers`, `uses`, `approval`).
88
+
89
+ ```ts
90
+ const org: DeploymentSpec = {
91
+ // ...
92
+ relationships: [
93
+ {
94
+ source: 'my-workflow',
95
+ target: 'email-notification',
96
+ type: 'triggers'
97
+ }
98
+ ],
99
+ humanCheckpoints: [
100
+ {
101
+ id: 'approval-gate',
102
+ label: 'Approve before sending',
103
+ routesTo: { resourceType: 'workflow', resourceId: 'my-workflow' }
104
+ }
105
+ ]
106
+ }
107
+ ```
108
+
109
+ Full relationship and checkpoint types are defined in `@elevasis/sdk` (`DeploymentSpec`). The generated `docs/resources.md` topology map will reflect these in the Topology Relationships, Triggers, and Human Checkpoints sections after regeneration.
110
+
111
+ ---
112
+
113
+ ## 4. (Optional) Map to a domain
114
+
115
+ To make the resource referenceable from the org model (so the Operations graph and Command View can link to it), add an entry to `resourceMappings` in `foundations/config/organization-model.ts`:
116
+
117
+ ```ts
118
+ resourceMappings: [
119
+ {
120
+ resourceId: 'my-workflow',
121
+ resourceType: 'workflow',
122
+ domainId: 'operations',
123
+ label: 'My Workflow'
124
+ }
125
+ ]
126
+ ```
127
+
128
+ See `OrganizationModelResourceMapping` in [contracts.md](../reference/contracts.md) for the full shape.
129
+
130
+ ---
131
+
132
+ ## 5. Regenerate the topology map
133
+
134
+ ```bash
135
+ pnpm generate-resources
136
+ ```
137
+
138
+ Open `docs/resources.md` and confirm:
139
+
140
+ - Section 1 (Workflows table) lists the new resource with correct `resourceId`, `version`, and `status`.
141
+ - Section 2 (Topology Relationships) shows any declared `relationships` edges.
142
+ - Sections 3-6 (Triggers, Integrations, Human Checkpoints, External Resources) show any relevant declarations.
143
+ - Section 7 (Schema Signatures) includes the new resource's input/output field list.
144
+
145
+ ---
146
+
147
+ ## 6. Verify
148
+
149
+ Validate and deploy:
150
+
151
+ ```bash
152
+ pnpm -C operations run check # validate resource definitions
153
+ pnpm -C operations run deploy # deploy to dev
154
+ ```
155
+
156
+ Execute via the platform CLI from the project root:
157
+
158
+ ```bash
159
+ pnpm exec elevasis describe Elevasis/my-workflow
160
+ pnpm exec elevasis exec Elevasis/my-workflow --input '{"field": "value"}'
161
+ ```
162
+
163
+ Use `--async` for long-running resources. Use `pnpm exec elevasis --prod exec ...` (flag before `exec`) for production. See [workflow-recipes.md](../operations/workflow-recipes.md) recipe 3 for the frontend trigger pattern.
@@ -0,0 +1,152 @@
1
+ ---
2
+ title: Gate by Feature or Admin
3
+ description: Decision table and step-by-step recipes for gating routes, nav items, and UI elements by feature flag or admin role.
4
+ ---
5
+
6
+ # Gate by Feature or Admin
7
+
8
+ End-to-end: gate a route, nav item, or UI element. Steps are sequential.
9
+
10
+ See [glossary.md](../reference/glossary.md) under **FeatureGuard**, **AdminGuard**, **accessFeatureKey**, **featureKey**, **Settings asymmetry**, and **MembershipFeatureConfig**. See [contracts.md](../reference/contracts.md) for `MembershipFeatureConfig` shape and the settings-asymmetry callout.
11
+
12
+ For the three-concept model in full detail, see [feature-flags-and-gating.md](../ui/feature-flags-and-gating.md).
13
+
14
+ ---
15
+
16
+ ## 1. Decide: feature-level or admin-level?
17
+
18
+ | Scenario | Gate to use |
19
+ | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
20
+ | Surface should be off by default for all members, toggled org-wide or per member | `FeatureGuard` + `featureKey` on nav entry |
21
+ | Surface is always visible to authenticated members but restricted to admins only | `AdminGuard` + `requiresAdmin` on nav entry |
22
+ | Surface is both feature-gated and admin-only | Both: `FeatureGuard` wrapping `AdminGuard`, plus both nav-entry fields |
23
+
24
+ Do not substitute one for the other. `FeatureGuard` reads feature flags; `AdminGuard` reads admin role. They are independent.
25
+
26
+ ---
27
+
28
+ ## 2. Feature gate -- org level
29
+
30
+ Ensure the key exists in the org model. File: `foundations/config/organization-model.ts`.
31
+
32
+ ```ts
33
+ // In defineOrganizationModel call:
34
+ features: { enabled: { ..., analytics: false } }
35
+
36
+ // In featuresEnabled resolver:
37
+ analytics: resolvedOrganizationModel.features.enabled.analytics ?? false
38
+ ```
39
+
40
+ If the key is template-local (not a platform `OrganizationModelFeatureKey`), add it to `FoundationLegacyFeatureKey` first. See [add-a-feature.md](add-a-feature.md) step 2.
41
+
42
+ Toggle `analytics: true` to enable for all members by default.
43
+
44
+ ---
45
+
46
+ ## 3. Feature gate -- route level
47
+
48
+ Wrap the route layout with `FeatureGuard` inside `ProtectedRoute`. The template-local `FeatureGuard` resolves key aliases automatically.
49
+
50
+ ```tsx
51
+ import { ProtectedRoute } from '@/features/auth'
52
+ import { FeatureGuard } from '@/features/auth/guards/FeatureGuard'
53
+ import { createFileRoute, Outlet } from '@tanstack/react-router'
54
+
55
+ export const Route = createFileRoute('/analytics')({ component: AnalyticsLayout })
56
+
57
+ function AnalyticsLayout() {
58
+ return (
59
+ <ProtectedRoute>
60
+ <FeatureGuard featureKey="analytics">
61
+ <Outlet />
62
+ </FeatureGuard>
63
+ </ProtectedRoute>
64
+ )
65
+ }
66
+ ```
67
+
68
+ `FeatureGuard` redirects to `/` with a Mantine notification when the feature is off. All child routes under this layout are automatically protected -- no need to repeat the guard in children.
69
+
70
+ Import path: `@/features/auth/guards/FeatureGuard` (template-local). Do not import `FeatureGuard` from `@elevasis/ui/features` -- that version does not close over the local key aliases. See [feature-flags-and-gating.md](../ui/feature-flags-and-gating.md) for the import-paths table.
71
+
72
+ ---
73
+
74
+ ## 4. Admin gate -- route level
75
+
76
+ Wrap with `AdminGuard` inside `ProtectedRoute`. `AdminGuard` redirects non-admins to `redirectTo` (default `/`).
77
+
78
+ ```tsx
79
+ import { ProtectedRoute } from '@/features/auth'
80
+ import { AdminGuard } from '@elevasis/ui/auth'
81
+ import { createFileRoute, Outlet } from '@tanstack/react-router'
82
+
83
+ export const Route = createFileRoute('/admin')({ component: AdminLayout })
84
+
85
+ function AdminLayout() {
86
+ return (
87
+ <ProtectedRoute>
88
+ <AdminGuard>
89
+ <Outlet />
90
+ </AdminGuard>
91
+ </ProtectedRoute>
92
+ )
93
+ }
94
+ ```
95
+
96
+ Import path: `@elevasis/ui/auth` (published). Always nest inside `ProtectedRoute` -- the guard depends on the user profile being loaded.
97
+
98
+ ---
99
+
100
+ ## 5. Nav-item visibility
101
+
102
+ Declare `featureKey` on the nav entry to have the shell auto-hide it when the feature is off. Declare `requiresAdmin: true` to hide it for non-admin members.
103
+
104
+ ```ts
105
+ // In FeatureModule.navEntry (manifest-backed features):
106
+ navEntry: {
107
+ label: 'Analytics',
108
+ icon: IconChartBar,
109
+ link: '/analytics',
110
+ featureKey: 'analytics' // optional -- accessFeatureKey already gates the whole module
111
+ }
112
+
113
+ // In nav-items.ts (app-local nav):
114
+ { label: 'Analytics', icon: IconChartBar, link: '/analytics', featureKey: 'analytics' }
115
+ { label: 'Admin', icon: IconShield, link: '/admin', requiresAdmin: true }
116
+ ```
117
+
118
+ `featureKey` on a nav entry is a display hint only -- it does not protect the route. Always pair with a route-level `FeatureGuard`. See [glossary.md](../reference/glossary.md) under **accessFeatureKey vs featureKey** for the distinction.
119
+
120
+ ---
121
+
122
+ ## 6. Per-member override
123
+
124
+ `MembershipFeatureConfig.features` (stored in `org_memberships.config`) overrides org-level defaults per member. Full shape is in [contracts.md](../reference/contracts.md#membershipfeatureconfig).
125
+
126
+ ```ts
127
+ // Disable analytics for a specific member (stored in their membership record):
128
+ {
129
+ features: { acquisition: false }
130
+ }
131
+ ```
132
+
133
+ **Settings asymmetry -- read this before writing membership config.** `OrganizationModelFeatureKey` has 7 keys; `MembershipFeatureConfig.features` has only 6. The `settings` key is intentionally absent from membership config: settings access is controlled by `requiresAdmin` and `AdminGuard`, not per-member feature flags. Writing a `settings` key to `org_memberships.config` has no effect. See [contracts.md](../reference/contracts.md#membershipfeatureconfig) for the full callout, and [glossary.md](../reference/glossary.md) under **Settings asymmetry**.
134
+
135
+ Membership config is read/written directly via the Supabase client (`org_memberships.config` column). There is no dedicated API route for bulk updates.
136
+
137
+ ---
138
+
139
+ ## 7. Verify
140
+
141
+ State matrix -- confirm each combination:
142
+
143
+ | Org feature enabled | Member override | Admin | Expected result |
144
+ | ------------------- | --------------- | --------- | --------------------------------------------- |
145
+ | true | (absent) | any | Route accessible, nav visible |
146
+ | true | false | any | Route redirects, nav hidden |
147
+ | false | (absent) | any | Route redirects, nav hidden |
148
+ | false | true | any | Route redirects (org gate wins) |
149
+ | true | (absent) | non-admin | Admin-gated route redirects, admin nav hidden |
150
+ | true | (absent) | admin | Admin-gated route accessible, nav visible |
151
+
152
+ Check each gate independently: feature toggle in `foundations/config/organization-model.ts`, membership config in `org_memberships.config`, and admin status in the user profile.
@@ -0,0 +1,32 @@
1
+ ---
2
+ title: Pathway Recipes
3
+ description: Terse end-to-end walkthroughs for the three most common authoring tasks -- adding a feature, adding a resource, and gating access.
4
+ ---
5
+
6
+ # Pathway Recipes
7
+
8
+ Three sequential walkthroughs for common authoring tasks. Each recipe links into the reference docs rather than duplicating them.
9
+
10
+ Before starting, read [glossary.md](../reference/glossary.md) to disambiguate overloaded terms (Feature, Resource, accessFeatureKey, Settings asymmetry, Topology).
11
+
12
+ ---
13
+
14
+ ## Recipes
15
+
16
+ **[Add a Feature](add-a-feature.md)**
17
+ You want a new shell feature (e.g., `analytics`) with its own nav entry, sidebar, routes, and org-model gate. Covers org-model key declaration, `FeatureModule` manifest authoring, route creation, and gating.
18
+
19
+ **[Add a Resource](add-a-resource.md)**
20
+ You want a new workflow or agent deployed to the platform. Covers `WorkflowDefinition` authoring, `DeploymentSpec` registration, relationship declarations, domain mapping, and CLI verification.
21
+
22
+ **[Gate by Feature or Admin](gate-by-feature-or-admin.md)**
23
+ You want to restrict a route, nav item, or UI element by feature flag or admin role. Covers the decision table, `FeatureGuard`, `AdminGuard`, nav-entry visibility fields, per-member `MembershipFeatureConfig` overrides, and the settings-asymmetry gotcha.
24
+
25
+ ---
26
+
27
+ ## Reference docs these recipes link into
28
+
29
+ - [glossary.md](../reference/glossary.md) -- term disambiguation for Feature, Resource, accessFeatureKey, Topology, Settings asymmetry
30
+ - [contracts.md](../reference/contracts.md) -- TypeScript shapes: `FeatureModule`, `FeatureNavEntry`, `OrganizationModel`, `MembershipFeatureConfig`
31
+ - [feature-flags-and-gating.md](../ui/feature-flags-and-gating.md) -- full three-concept gating model
32
+ - [workflow-recipes.md](../operations/workflow-recipes.md) -- workflow anatomy, adapters, trigger patterns