@kelpie/server 0.10.0 → 0.12.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.
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +2 -0
- package/dist/app.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/actor.d.ts +3 -1
- package/dist/lib/actor.d.ts.map +1 -1
- package/dist/lib/actor.js.map +1 -1
- package/dist/lib/apiKeyScopes.d.ts +8 -0
- package/dist/lib/apiKeyScopes.d.ts.map +1 -0
- package/dist/lib/apiKeyScopes.js +166 -0
- package/dist/lib/apiKeyScopes.js.map +1 -0
- package/dist/lib/errors.d.ts +18 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +17 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/modules/activities/repository.d.ts +2 -0
- package/dist/modules/activities/repository.d.ts.map +1 -1
- package/dist/modules/activities/repository.js +9 -0
- package/dist/modules/activities/repository.js.map +1 -1
- package/dist/modules/agent-tasks/repository.d.ts +2 -0
- package/dist/modules/agent-tasks/repository.d.ts.map +1 -1
- package/dist/modules/agent-tasks/repository.js +9 -0
- package/dist/modules/agent-tasks/repository.js.map +1 -1
- package/dist/modules/api-keys/routes.d.ts.map +1 -1
- package/dist/modules/api-keys/routes.js +4 -1
- package/dist/modules/api-keys/routes.js.map +1 -1
- package/dist/modules/api-keys/schema.d.ts +43 -0
- package/dist/modules/api-keys/schema.d.ts.map +1 -1
- package/dist/modules/api-keys/schema.js +2 -0
- package/dist/modules/api-keys/schema.js.map +1 -1
- package/dist/modules/api-keys/scopeMiddleware.d.ts +8 -0
- package/dist/modules/api-keys/scopeMiddleware.d.ts.map +1 -0
- package/dist/modules/api-keys/scopeMiddleware.js +21 -0
- package/dist/modules/api-keys/scopeMiddleware.js.map +1 -0
- package/dist/modules/api-keys/service.d.ts +3 -1
- package/dist/modules/api-keys/service.d.ts.map +1 -1
- package/dist/modules/api-keys/service.js +26 -1
- package/dist/modules/api-keys/service.js.map +1 -1
- package/dist/modules/auth/credentials.d.ts.map +1 -1
- package/dist/modules/auth/credentials.js +2 -0
- package/dist/modules/auth/credentials.js.map +1 -1
- package/dist/modules/auth/index.d.ts.map +1 -1
- package/dist/modules/auth/index.js +21 -4
- package/dist/modules/auth/index.js.map +1 -1
- package/dist/modules/auth/repository.d.ts +2 -1
- package/dist/modules/auth/repository.d.ts.map +1 -1
- package/dist/modules/auth/repository.js +1 -0
- package/dist/modules/auth/repository.js.map +1 -1
- package/dist/modules/auth/routes.d.ts.map +1 -1
- package/dist/modules/auth/routes.js +2 -6
- package/dist/modules/auth/routes.js.map +1 -1
- package/dist/modules/auth/schema.d.ts +18 -1
- package/dist/modules/auth/schema.d.ts.map +1 -1
- package/dist/modules/auth/schema.js +12 -1
- package/dist/modules/auth/schema.js.map +1 -1
- package/dist/modules/auth/service.d.ts +18 -0
- package/dist/modules/auth/service.d.ts.map +1 -1
- package/dist/modules/auth/service.js +95 -6
- package/dist/modules/auth/service.js.map +1 -1
- package/dist/modules/auth/session.d.ts +12 -0
- package/dist/modules/auth/session.d.ts.map +1 -1
- package/dist/modules/auth/session.js +12 -0
- package/dist/modules/auth/session.js.map +1 -1
- package/dist/modules/consent-purposes/index.d.ts +1 -1
- package/dist/modules/consent-purposes/index.js +1 -1
- package/dist/modules/consent-purposes/schema.d.ts +3 -3
- package/dist/modules/consent-purposes/schema.js +3 -3
- package/dist/modules/consent-purposes/service.d.ts +1 -1
- package/dist/modules/consent-purposes/service.d.ts.map +1 -1
- package/dist/modules/consent-purposes/service.js +7 -16
- package/dist/modules/consent-purposes/service.js.map +1 -1
- package/dist/modules/consent-purposes/starters.d.ts +1 -1
- package/dist/modules/consent-purposes/tools.js +1 -1
- package/dist/modules/consent-purposes/tools.js.map +1 -1
- package/dist/modules/conversions/clearPointers.d.ts +10 -0
- package/dist/modules/conversions/clearPointers.d.ts.map +1 -0
- package/dist/modules/conversions/clearPointers.js +40 -0
- package/dist/modules/conversions/clearPointers.js.map +1 -0
- package/dist/modules/conversions/factory.d.ts +5 -0
- package/dist/modules/conversions/factory.d.ts.map +1 -0
- package/dist/modules/conversions/factory.js +18 -0
- package/dist/modules/conversions/factory.js.map +1 -0
- package/dist/modules/conversions/fieldMap.d.ts +55 -0
- package/dist/modules/conversions/fieldMap.d.ts.map +1 -0
- package/dist/modules/conversions/fieldMap.js +398 -0
- package/dist/modules/conversions/fieldMap.js.map +1 -0
- package/dist/modules/conversions/index.d.ts +7 -0
- package/dist/modules/conversions/index.d.ts.map +1 -0
- package/dist/modules/conversions/index.js +6 -0
- package/dist/modules/conversions/index.js.map +1 -0
- package/dist/modules/conversions/mcp.d.ts +7 -0
- package/dist/modules/conversions/mcp.d.ts.map +1 -0
- package/dist/modules/conversions/mcp.js +47 -0
- package/dist/modules/conversions/mcp.js.map +1 -0
- package/dist/modules/conversions/repoint.d.ts +19 -0
- package/dist/modules/conversions/repoint.d.ts.map +1 -0
- package/dist/modules/conversions/repoint.js +51 -0
- package/dist/modules/conversions/repoint.js.map +1 -0
- package/dist/modules/conversions/routes.d.ts +26 -0
- package/dist/modules/conversions/routes.d.ts.map +1 -0
- package/dist/modules/conversions/routes.js +23 -0
- package/dist/modules/conversions/routes.js.map +1 -0
- package/dist/modules/conversions/service.d.ts +28 -0
- package/dist/modules/conversions/service.d.ts.map +1 -0
- package/dist/modules/conversions/service.js +170 -0
- package/dist/modules/conversions/service.js.map +1 -0
- package/dist/modules/conversions/wire.d.ts +4 -0
- package/dist/modules/conversions/wire.d.ts.map +1 -0
- package/dist/modules/conversions/wire.js +28 -0
- package/dist/modules/conversions/wire.js.map +1 -0
- package/dist/modules/deals/events.d.ts +9 -0
- package/dist/modules/deals/events.d.ts.map +1 -1
- package/dist/modules/deals/events.js +4 -0
- package/dist/modules/deals/events.js.map +1 -1
- package/dist/modules/deals/index.d.ts.map +1 -1
- package/dist/modules/deals/index.js +4 -2
- package/dist/modules/deals/index.js.map +1 -1
- package/dist/modules/deals/routes.d.ts +2 -0
- package/dist/modules/deals/routes.d.ts.map +1 -1
- package/dist/modules/deals/routes.js +8 -1
- package/dist/modules/deals/routes.js.map +1 -1
- package/dist/modules/deals/schema.d.ts +34 -0
- package/dist/modules/deals/schema.d.ts.map +1 -1
- package/dist/modules/deals/schema.js +7 -2
- package/dist/modules/deals/schema.js.map +1 -1
- package/dist/modules/deals/service.d.ts.map +1 -1
- package/dist/modules/deals/service.js +2 -0
- package/dist/modules/deals/service.js.map +1 -1
- package/dist/modules/deals/tools.d.ts +2 -1
- package/dist/modules/deals/tools.d.ts.map +1 -1
- package/dist/modules/deals/tools.js +3 -1
- package/dist/modules/deals/tools.js.map +1 -1
- package/dist/modules/decisions/repository.d.ts +2 -1
- package/dist/modules/decisions/repository.d.ts.map +1 -1
- package/dist/modules/decisions/repository.js +9 -1
- package/dist/modules/decisions/repository.js.map +1 -1
- package/dist/modules/enquiries/events.d.ts +6 -2
- package/dist/modules/enquiries/events.d.ts.map +1 -1
- package/dist/modules/enquiries/events.js +5 -1
- package/dist/modules/enquiries/events.js.map +1 -1
- package/dist/modules/enquiries/index.d.ts.map +1 -1
- package/dist/modules/enquiries/index.js +4 -2
- package/dist/modules/enquiries/index.js.map +1 -1
- package/dist/modules/enquiries/routes.d.ts +2 -0
- package/dist/modules/enquiries/routes.d.ts.map +1 -1
- package/dist/modules/enquiries/routes.js +9 -9
- package/dist/modules/enquiries/routes.js.map +1 -1
- package/dist/modules/enquiries/schema.d.ts +36 -1
- package/dist/modules/enquiries/schema.d.ts.map +1 -1
- package/dist/modules/enquiries/schema.js +9 -3
- package/dist/modules/enquiries/schema.js.map +1 -1
- package/dist/modules/enquiries/service.d.ts +0 -8
- package/dist/modules/enquiries/service.d.ts.map +1 -1
- package/dist/modules/enquiries/service.js +3 -95
- package/dist/modules/enquiries/service.js.map +1 -1
- package/dist/modules/enquiries/tools.d.ts +2 -1
- package/dist/modules/enquiries/tools.d.ts.map +1 -1
- package/dist/modules/enquiries/tools.js +4 -16
- package/dist/modules/enquiries/tools.js.map +1 -1
- package/dist/modules/forms/applyMappedFields.d.ts +20 -0
- package/dist/modules/forms/applyMappedFields.d.ts.map +1 -0
- package/dist/modules/forms/applyMappedFields.js +169 -0
- package/dist/modules/forms/applyMappedFields.js.map +1 -0
- package/dist/modules/forms/applySubmissionFields.d.ts +18 -0
- package/dist/modules/forms/applySubmissionFields.d.ts.map +1 -0
- package/dist/modules/forms/applySubmissionFields.js +230 -0
- package/dist/modules/forms/applySubmissionFields.js.map +1 -0
- package/dist/modules/forms/fields.d.ts +7 -2
- package/dist/modules/forms/fields.d.ts.map +1 -1
- package/dist/modules/forms/fields.js +17 -6
- package/dist/modules/forms/fields.js.map +1 -1
- package/dist/modules/forms/mapping.d.ts +8 -2
- package/dist/modules/forms/mapping.d.ts.map +1 -1
- package/dist/modules/forms/mapping.js +11 -0
- package/dist/modules/forms/mapping.js.map +1 -1
- package/dist/modules/forms/repository.d.ts +0 -5
- package/dist/modules/forms/repository.d.ts.map +1 -1
- package/dist/modules/forms/repository.js +0 -2
- package/dist/modules/forms/repository.js.map +1 -1
- package/dist/modules/forms/routes.d.ts +2 -30
- package/dist/modules/forms/routes.d.ts.map +1 -1
- package/dist/modules/forms/routes.js +2 -2
- package/dist/modules/forms/routes.js.map +1 -1
- package/dist/modules/forms/schema.d.ts.map +1 -1
- package/dist/modules/forms/schema.js +1 -2
- package/dist/modules/forms/schema.js.map +1 -1
- package/dist/modules/forms/service.d.ts.map +1 -1
- package/dist/modules/forms/service.js +18 -3
- package/dist/modules/forms/service.js.map +1 -1
- package/dist/modules/forms/starters.d.ts +31 -0
- package/dist/modules/forms/starters.d.ts.map +1 -0
- package/dist/modules/forms/starters.js +94 -0
- package/dist/modules/forms/starters.js.map +1 -0
- package/dist/modules/forms/submission.d.ts +1 -0
- package/dist/modules/forms/submission.d.ts.map +1 -1
- package/dist/modules/forms/submission.js +58 -37
- package/dist/modules/forms/submission.js.map +1 -1
- package/dist/modules/import-export/customFieldCsv.d.ts +9 -0
- package/dist/modules/import-export/customFieldCsv.d.ts.map +1 -0
- package/dist/modules/import-export/customFieldCsv.js +39 -0
- package/dist/modules/import-export/customFieldCsv.js.map +1 -0
- package/dist/modules/import-export/customFieldImport.d.ts +19 -0
- package/dist/modules/import-export/customFieldImport.d.ts.map +1 -0
- package/dist/modules/import-export/customFieldImport.js +76 -0
- package/dist/modules/import-export/customFieldImport.js.map +1 -0
- package/dist/modules/import-export/drafts.d.ts +57 -3
- package/dist/modules/import-export/drafts.d.ts.map +1 -1
- package/dist/modules/import-export/drafts.js +65 -3
- package/dist/modules/import-export/drafts.js.map +1 -1
- package/dist/modules/import-export/exportRows.d.ts +15 -13
- package/dist/modules/import-export/exportRows.d.ts.map +1 -1
- package/dist/modules/import-export/exportRows.js +99 -26
- package/dist/modules/import-export/exportRows.js.map +1 -1
- package/dist/modules/import-export/plan.d.ts +42 -11
- package/dist/modules/import-export/plan.d.ts.map +1 -1
- package/dist/modules/import-export/plan.js +198 -56
- package/dist/modules/import-export/plan.js.map +1 -1
- package/dist/modules/import-export/repository.d.ts +58 -2
- package/dist/modules/import-export/repository.d.ts.map +1 -1
- package/dist/modules/import-export/repository.js +201 -12
- package/dist/modules/import-export/repository.js.map +1 -1
- package/dist/modules/import-export/routes.d.ts.map +1 -1
- package/dist/modules/import-export/routes.js +5 -5
- package/dist/modules/import-export/routes.js.map +1 -1
- package/dist/modules/import-export/service.d.ts +8 -3
- package/dist/modules/import-export/service.d.ts.map +1 -1
- package/dist/modules/import-export/service.js +133 -40
- package/dist/modules/import-export/service.js.map +1 -1
- package/dist/modules/import-export/streams.d.ts +2 -2
- package/dist/modules/import-export/streams.d.ts.map +1 -1
- package/dist/modules/import-export/streams.js +50 -9
- package/dist/modules/import-export/streams.js.map +1 -1
- package/dist/modules/import-export/tools.d.ts.map +1 -1
- package/dist/modules/import-export/tools.js +13 -7
- package/dist/modules/import-export/tools.js.map +1 -1
- package/dist/modules/import-export/validation.d.ts +5 -1
- package/dist/modules/import-export/validation.d.ts.map +1 -1
- package/dist/modules/import-export/validation.js +89 -2
- package/dist/modules/import-export/validation.js.map +1 -1
- package/dist/modules/import-export/writes.d.ts +2 -1
- package/dist/modules/import-export/writes.d.ts.map +1 -1
- package/dist/modules/import-export/writes.js +358 -25
- package/dist/modules/import-export/writes.js.map +1 -1
- package/dist/modules/lists/repository.d.ts +0 -1
- package/dist/modules/lists/repository.d.ts.map +1 -1
- package/dist/modules/lists/repository.js +0 -1
- package/dist/modules/lists/repository.js.map +1 -1
- package/dist/modules/lists/routes.d.ts +0 -2
- package/dist/modules/lists/routes.d.ts.map +1 -1
- package/dist/modules/lists/routes.js +0 -8
- package/dist/modules/lists/routes.js.map +1 -1
- package/dist/modules/lists/schema.d.ts +0 -17
- package/dist/modules/lists/schema.d.ts.map +1 -1
- package/dist/modules/lists/schema.js +0 -10
- package/dist/modules/lists/schema.js.map +1 -1
- package/dist/modules/lists/service.d.ts +2 -14
- package/dist/modules/lists/service.d.ts.map +1 -1
- package/dist/modules/lists/service.js +7 -53
- package/dist/modules/lists/service.js.map +1 -1
- package/dist/modules/lists/starters.d.ts +12 -0
- package/dist/modules/lists/starters.d.ts.map +1 -0
- package/dist/modules/lists/starters.js +4 -0
- package/dist/modules/lists/starters.js.map +1 -0
- package/dist/modules/mcp/protocol.d.ts.map +1 -1
- package/dist/modules/mcp/protocol.js +13 -0
- package/dist/modules/mcp/protocol.js.map +1 -1
- package/dist/modules/notes/repository.d.ts +2 -0
- package/dist/modules/notes/repository.d.ts.map +1 -1
- package/dist/modules/notes/repository.js +9 -0
- package/dist/modules/notes/repository.js.map +1 -1
- package/dist/modules/opportunities/events.d.ts +9 -0
- package/dist/modules/opportunities/events.d.ts.map +1 -1
- package/dist/modules/opportunities/events.js +4 -0
- package/dist/modules/opportunities/events.js.map +1 -1
- package/dist/modules/opportunities/index.d.ts.map +1 -1
- package/dist/modules/opportunities/index.js +4 -2
- package/dist/modules/opportunities/index.js.map +1 -1
- package/dist/modules/opportunities/routes.d.ts +2 -0
- package/dist/modules/opportunities/routes.d.ts.map +1 -1
- package/dist/modules/opportunities/routes.js +8 -1
- package/dist/modules/opportunities/routes.js.map +1 -1
- package/dist/modules/opportunities/schema.d.ts +34 -0
- package/dist/modules/opportunities/schema.d.ts.map +1 -1
- package/dist/modules/opportunities/schema.js +7 -2
- package/dist/modules/opportunities/schema.js.map +1 -1
- package/dist/modules/opportunities/service.d.ts.map +1 -1
- package/dist/modules/opportunities/service.js +2 -0
- package/dist/modules/opportunities/service.js.map +1 -1
- package/dist/modules/opportunities/tools.d.ts +2 -1
- package/dist/modules/opportunities/tools.d.ts.map +1 -1
- package/dist/modules/opportunities/tools.js +3 -1
- package/dist/modules/opportunities/tools.js.map +1 -1
- package/dist/modules/partnerships/events.d.ts +9 -0
- package/dist/modules/partnerships/events.d.ts.map +1 -1
- package/dist/modules/partnerships/events.js +4 -0
- package/dist/modules/partnerships/events.js.map +1 -1
- package/dist/modules/partnerships/index.d.ts.map +1 -1
- package/dist/modules/partnerships/index.js +4 -2
- package/dist/modules/partnerships/index.js.map +1 -1
- package/dist/modules/partnerships/routes.d.ts +2 -0
- package/dist/modules/partnerships/routes.d.ts.map +1 -1
- package/dist/modules/partnerships/routes.js +8 -1
- package/dist/modules/partnerships/routes.js.map +1 -1
- package/dist/modules/partnerships/schema.d.ts +34 -0
- package/dist/modules/partnerships/schema.d.ts.map +1 -1
- package/dist/modules/partnerships/schema.js +7 -2
- package/dist/modules/partnerships/schema.js.map +1 -1
- package/dist/modules/partnerships/service.d.ts.map +1 -1
- package/dist/modules/partnerships/service.js +2 -0
- package/dist/modules/partnerships/service.js.map +1 -1
- package/dist/modules/partnerships/tools.d.ts +2 -1
- package/dist/modules/partnerships/tools.d.ts.map +1 -1
- package/dist/modules/partnerships/tools.js +3 -1
- package/dist/modules/partnerships/tools.js.map +1 -1
- package/dist/modules/people/personConsentWrites.d.ts +1 -1
- package/dist/modules/people/schema.js +1 -1
- package/dist/modules/people/schema.js.map +1 -1
- package/dist/modules/plans/repository.d.ts +2 -0
- package/dist/modules/plans/repository.d.ts.map +1 -1
- package/dist/modules/plans/repository.js +9 -0
- package/dist/modules/plans/repository.js.map +1 -1
- package/dist/modules/raises/events.d.ts +9 -0
- package/dist/modules/raises/events.d.ts.map +1 -1
- package/dist/modules/raises/events.js +4 -0
- package/dist/modules/raises/events.js.map +1 -1
- package/dist/modules/raises/index.d.ts.map +1 -1
- package/dist/modules/raises/index.js +4 -2
- package/dist/modules/raises/index.js.map +1 -1
- package/dist/modules/raises/routes.d.ts +2 -0
- package/dist/modules/raises/routes.d.ts.map +1 -1
- package/dist/modules/raises/routes.js +8 -1
- package/dist/modules/raises/routes.js.map +1 -1
- package/dist/modules/raises/schema.d.ts +34 -0
- package/dist/modules/raises/schema.d.ts.map +1 -1
- package/dist/modules/raises/schema.js +7 -2
- package/dist/modules/raises/schema.js.map +1 -1
- package/dist/modules/raises/service.d.ts.map +1 -1
- package/dist/modules/raises/service.js +2 -0
- package/dist/modules/raises/service.js.map +1 -1
- package/dist/modules/raises/tools.d.ts +2 -1
- package/dist/modules/raises/tools.d.ts.map +1 -1
- package/dist/modules/raises/tools.js +3 -1
- package/dist/modules/raises/tools.js.map +1 -1
- package/dist/modules/workspace/routes.d.ts +0 -2
- package/dist/modules/workspace/routes.d.ts.map +1 -1
- package/dist/modules/workspace/routes.js +0 -6
- package/dist/modules/workspace/routes.js.map +1 -1
- package/dist/modules/workspace/schema.d.ts +0 -34
- package/dist/modules/workspace/schema.d.ts.map +1 -1
- package/dist/modules/workspace/schema.js +0 -2
- package/dist/modules/workspace/schema.js.map +1 -1
- package/dist/modules/workspace/seedStarterForms.d.ts +17 -0
- package/dist/modules/workspace/seedStarterForms.d.ts.map +1 -0
- package/dist/modules/workspace/seedStarterForms.js +71 -0
- package/dist/modules/workspace/seedStarterForms.js.map +1 -0
- package/dist/modules/workspace/service.d.ts +0 -4
- package/dist/modules/workspace/service.d.ts.map +1 -1
- package/dist/modules/workspace/service.js +20 -10
- package/dist/modules/workspace/service.js.map +1 -1
- package/dist/modules/workspace/tools.js +1 -1
- package/dist/modules/workspace/tools.js.map +1 -1
- package/dist/runtime/module.d.ts +63 -1
- package/dist/runtime/module.d.ts.map +1 -1
- package/dist/runtime/registry.d.ts.map +1 -1
- package/dist/runtime/registry.js +40 -2
- package/dist/runtime/registry.js.map +1 -1
- package/dist/testing/fixtures.d.ts.map +1 -1
- package/dist/testing/fixtures.js +1 -0
- package/dist/testing/fixtures.js.map +1 -1
- package/migrations/0037_drop_lists_consent_purpose_id.sql +2 -0
- package/migrations/0038_smart_white_queen.sql +2 -0
- package/migrations/0039_form_map_to_open.sql +1 -0
- package/migrations/0040_pipeline_converted_to.sql +20 -0
- package/migrations/0041_api_key_scopes.sql +1 -0
- package/migrations/0042_drop_workspace_identity.sql +2 -0
- package/migrations/0043_external_sign_in.sql +2 -0
- package/migrations/meta/0038_snapshot.json +6554 -0
- package/migrations/meta/_journal.json +49 -0
- package/package.json +2 -2
- package/src/app.ts +3 -0
- package/src/index.ts +13 -1
- package/src/lib/actor.ts +3 -1
- package/src/lib/apiKeyScopes.ts +213 -0
- package/src/lib/errors.ts +30 -0
- package/src/modules/activities/repository.ts +24 -0
- package/src/modules/agent-tasks/repository.ts +24 -0
- package/src/modules/api-keys/routes.ts +5 -0
- package/src/modules/api-keys/schema.ts +2 -0
- package/src/modules/api-keys/scopeMiddleware.ts +30 -0
- package/src/modules/api-keys/service.ts +36 -2
- package/src/modules/auth/credentials.ts +4 -0
- package/src/modules/auth/index.ts +25 -4
- package/src/modules/auth/repository.ts +2 -1
- package/src/modules/auth/routes.ts +2 -8
- package/src/modules/auth/schema.ts +12 -1
- package/src/modules/auth/service.ts +143 -6
- package/src/modules/auth/session.ts +14 -0
- package/src/modules/consent-purposes/index.ts +1 -1
- package/src/modules/consent-purposes/schema.ts +3 -3
- package/src/modules/consent-purposes/service.ts +7 -16
- package/src/modules/consent-purposes/starters.ts +1 -1
- package/src/modules/consent-purposes/tools.ts +1 -1
- package/src/modules/conversions/clearPointers.ts +81 -0
- package/src/modules/conversions/factory.ts +20 -0
- package/src/modules/conversions/fieldMap.ts +548 -0
- package/src/modules/conversions/index.ts +6 -0
- package/src/modules/conversions/mcp.ts +71 -0
- package/src/modules/conversions/repoint.ts +146 -0
- package/src/modules/conversions/routes.ts +68 -0
- package/src/modules/conversions/service.ts +310 -0
- package/src/modules/conversions/wire.ts +42 -0
- package/src/modules/deals/events.ts +9 -0
- package/src/modules/deals/index.ts +4 -2
- package/src/modules/deals/routes.ts +11 -1
- package/src/modules/deals/schema.ts +10 -2
- package/src/modules/deals/service.ts +3 -0
- package/src/modules/deals/tools.ts +9 -1
- package/src/modules/decisions/repository.ts +23 -1
- package/src/modules/enquiries/events.ts +8 -2
- package/src/modules/enquiries/index.ts +4 -2
- package/src/modules/enquiries/routes.ts +11 -13
- package/src/modules/enquiries/schema.ts +12 -3
- package/src/modules/enquiries/service.ts +3 -150
- package/src/modules/enquiries/tools.ts +9 -18
- package/src/modules/forms/applyMappedFields.ts +248 -0
- package/src/modules/forms/applySubmissionFields.ts +435 -0
- package/src/modules/forms/fields.ts +31 -7
- package/src/modules/forms/mapping.ts +20 -3
- package/src/modules/forms/repository.ts +0 -7
- package/src/modules/forms/routes.ts +1 -2
- package/src/modules/forms/schema.ts +0 -2
- package/src/modules/forms/service.ts +31 -4
- package/src/modules/forms/starters.ts +129 -0
- package/src/modules/forms/submission.ts +135 -69
- package/src/modules/import-export/customFieldCsv.ts +55 -0
- package/src/modules/import-export/customFieldImport.ts +111 -0
- package/src/modules/import-export/drafts.ts +151 -3
- package/src/modules/import-export/exportRows.ts +222 -68
- package/src/modules/import-export/plan.ts +321 -67
- package/src/modules/import-export/repository.ts +356 -14
- package/src/modules/import-export/routes.ts +8 -8
- package/src/modules/import-export/service.ts +208 -45
- package/src/modules/import-export/streams.ts +95 -13
- package/src/modules/import-export/tools.ts +14 -6
- package/src/modules/import-export/validation.ts +128 -0
- package/src/modules/import-export/writes.ts +559 -27
- package/src/modules/lists/repository.ts +0 -2
- package/src/modules/lists/routes.ts +0 -8
- package/src/modules/lists/schema.ts +0 -10
- package/src/modules/lists/service.ts +9 -107
- package/src/modules/lists/starters.ts +16 -0
- package/src/modules/mcp/protocol.ts +18 -0
- package/src/modules/notes/repository.ts +24 -0
- package/src/modules/opportunities/events.ts +9 -0
- package/src/modules/opportunities/index.ts +4 -2
- package/src/modules/opportunities/routes.ts +11 -1
- package/src/modules/opportunities/schema.ts +10 -2
- package/src/modules/opportunities/service.ts +3 -0
- package/src/modules/opportunities/tools.ts +9 -1
- package/src/modules/partnerships/events.ts +9 -0
- package/src/modules/partnerships/index.ts +4 -2
- package/src/modules/partnerships/routes.ts +11 -1
- package/src/modules/partnerships/schema.ts +10 -2
- package/src/modules/partnerships/service.ts +3 -0
- package/src/modules/partnerships/tools.ts +9 -1
- package/src/modules/people/personConsentWrites.ts +1 -1
- package/src/modules/people/schema.ts +1 -1
- package/src/modules/plans/repository.ts +24 -0
- package/src/modules/raises/events.ts +9 -0
- package/src/modules/raises/index.ts +4 -2
- package/src/modules/raises/routes.ts +11 -1
- package/src/modules/raises/schema.ts +10 -2
- package/src/modules/raises/service.ts +3 -0
- package/src/modules/raises/tools.ts +9 -1
- package/src/modules/workspace/routes.ts +0 -6
- package/src/modules/workspace/schema.ts +0 -2
- package/src/modules/workspace/seedStarterForms.ts +98 -0
- package/src/modules/workspace/service.ts +23 -15
- package/src/modules/workspace/tools.ts +1 -1
- package/src/runtime/module.ts +70 -1
- package/src/runtime/registry.ts +54 -0
- package/src/testing/fixtures.ts +1 -0
|
@@ -21,6 +21,7 @@ import type { Actor } from '../auth/actor.ts'
|
|
|
21
21
|
import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
|
|
22
22
|
import './events.ts'
|
|
23
23
|
import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
|
|
24
|
+
import { clearConversionPointersToTarget } from '../conversions/clearPointers.ts'
|
|
24
25
|
import * as companyRepository from '../companies/repository.ts'
|
|
25
26
|
import type { CustomFieldValuesValidator } from '../custom-fields/values.ts'
|
|
26
27
|
import * as personLinks from '../personLinks.ts'
|
|
@@ -488,6 +489,8 @@ export function createDealsService(dependencies: DealsDependencies): DealsServic
|
|
|
488
489
|
await dependencies.transaction(async ({ tx, events }) => {
|
|
489
490
|
await require(workspaceId, id)
|
|
490
491
|
|
|
492
|
+
await clearConversionPointersToTarget(tx, workspaceId, 'deal', id)
|
|
493
|
+
|
|
491
494
|
// Form submissions unlink themselves through `set null`; notes,
|
|
492
495
|
// activities, decisions, plan items, and person_links have no key back
|
|
493
496
|
// to the deal, so they are removed here, in the same transaction.
|
|
@@ -2,6 +2,8 @@ import { z } from 'zod'
|
|
|
2
2
|
|
|
3
3
|
import type { McpToolRegistry } from '../../runtime/module.ts'
|
|
4
4
|
import { idArg, idSetArg, listWindowShape, registerCrudTools, termArg, toSet } from '../crudTools.ts'
|
|
5
|
+
import type { ConversionsService } from '../conversions/index.ts'
|
|
6
|
+
import { registerPipelineConvertTool } from '../conversions/mcp.ts'
|
|
5
7
|
import { createBody, dealResponse, toCreateInput, toUpdateInput, updateBody } from './routes.ts'
|
|
6
8
|
import type { DealsService } from './service.ts'
|
|
7
9
|
|
|
@@ -15,7 +17,11 @@ const listArgs = z.strictObject({
|
|
|
15
17
|
person_id: idSetArg.optional().describe('Only deals one of these people is a contact on.'),
|
|
16
18
|
})
|
|
17
19
|
|
|
18
|
-
export function registerDealsTools(
|
|
20
|
+
export function registerDealsTools(
|
|
21
|
+
mcp: McpToolRegistry,
|
|
22
|
+
service: DealsService,
|
|
23
|
+
conversions: ConversionsService,
|
|
24
|
+
): void {
|
|
19
25
|
registerCrudTools(mcp, {
|
|
20
26
|
resource: 'deals',
|
|
21
27
|
subject: 'deal',
|
|
@@ -36,4 +42,6 @@ export function registerDealsTools(mcp: McpToolRegistry, service: DealsService):
|
|
|
36
42
|
updateArgs: updateBody.extend({ id: idArg }),
|
|
37
43
|
toUpdateInput,
|
|
38
44
|
})
|
|
45
|
+
|
|
46
|
+
registerPipelineConvertTool(mcp, conversions, 'deal')
|
|
39
47
|
}
|
|
@@ -191,7 +191,29 @@ export async function deleteForTarget(
|
|
|
191
191
|
return deleted.length
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
/**
|
|
194
|
+
/** Moves every decision from one target to another inside a conversion transaction. */
|
|
195
|
+
export async function repointForTarget(
|
|
196
|
+
db: Queryable,
|
|
197
|
+
workspaceId: string,
|
|
198
|
+
fromType: string,
|
|
199
|
+
fromId: string,
|
|
200
|
+
toType: string,
|
|
201
|
+
toId: string,
|
|
202
|
+
): Promise<number> {
|
|
203
|
+
const updated = await db
|
|
204
|
+
.update(decisions)
|
|
205
|
+
.set({ targetType: toType, targetId: toId })
|
|
206
|
+
.where(
|
|
207
|
+
and(
|
|
208
|
+
eq(decisions.workspaceId, workspaceId),
|
|
209
|
+
eq(decisions.targetType, fromType),
|
|
210
|
+
eq(decisions.targetId, fromId),
|
|
211
|
+
),
|
|
212
|
+
)
|
|
213
|
+
.returning({ id: decisions.id })
|
|
214
|
+
|
|
215
|
+
return updated.length
|
|
216
|
+
}
|
|
195
217
|
export async function memberExists(
|
|
196
218
|
db: Queryable,
|
|
197
219
|
workspaceId: string,
|
|
@@ -18,7 +18,11 @@ export const enquiriesEvents = {
|
|
|
18
18
|
* outside Kelpie subscribe to `record.created` on the deal instead. Kept for
|
|
19
19
|
* internal listeners that want the semantic signal.
|
|
20
20
|
*/
|
|
21
|
-
'enquiries.enquiry.converted': z.object({
|
|
21
|
+
'enquiries.enquiry.converted': z.object({
|
|
22
|
+
dealId: z.string().optional(),
|
|
23
|
+
targetType: z.string(),
|
|
24
|
+
targetId: z.string(),
|
|
25
|
+
}),
|
|
22
26
|
} satisfies ModuleEventCatalog
|
|
23
27
|
|
|
24
28
|
export type EnquiryCreatedData = Record<string, never>
|
|
@@ -31,7 +35,9 @@ export interface EnquiryStageChangedData {
|
|
|
31
35
|
readonly toStageId: string
|
|
32
36
|
}
|
|
33
37
|
export interface EnquiryConvertedData {
|
|
34
|
-
readonly dealId
|
|
38
|
+
readonly dealId?: string | undefined
|
|
39
|
+
readonly targetType: string
|
|
40
|
+
readonly targetId: string
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
declare module '../../runtime/events.ts' {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { KelpieModule } from '../../runtime/module.ts'
|
|
2
2
|
import { createActivityRecorder } from '../activities/index.ts'
|
|
3
|
+
import { createConversionsFromContext } from '../conversions/index.ts'
|
|
3
4
|
import { createCustomFieldValues } from '../custom-fields/index.ts'
|
|
4
5
|
import { enquiriesEvents } from './events.ts'
|
|
5
6
|
import { mountEnquiriesRoutes } from './routes.ts'
|
|
@@ -24,6 +25,7 @@ export function createEnquiriesModule(migrationsDirectory: string): KelpieModule
|
|
|
24
25
|
events: enquiriesEvents,
|
|
25
26
|
|
|
26
27
|
register(context) {
|
|
28
|
+
const conversions = createConversionsFromContext(context)
|
|
27
29
|
const service = createEnquiriesService({
|
|
28
30
|
db: context.db,
|
|
29
31
|
transaction: context.transaction,
|
|
@@ -39,10 +41,10 @@ export function createEnquiriesModule(migrationsDirectory: string): KelpieModule
|
|
|
39
41
|
context.schema(schema, migrationsDirectory)
|
|
40
42
|
|
|
41
43
|
context.routes((router) => {
|
|
42
|
-
mountEnquiriesRoutes(router, { db: context.db, now: context.now, service })
|
|
44
|
+
mountEnquiriesRoutes(router, { db: context.db, now: context.now, service, conversions })
|
|
43
45
|
})
|
|
44
46
|
|
|
45
|
-
registerEnquiriesTools(context.mcp, service)
|
|
47
|
+
registerEnquiriesTools(context.mcp, service, conversions)
|
|
46
48
|
|
|
47
49
|
return Promise.resolve()
|
|
48
50
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { customFieldsPatchShape } from '@kelpie/schemas'
|
|
1
|
+
import { convertEnquiryBody, convertedToResponse, customFieldsPatchShape } from '@kelpie/schemas'
|
|
2
2
|
import type { Context, Hono } from 'hono'
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
@@ -7,7 +7,8 @@ import type { Actor } from '../auth/actor.ts'
|
|
|
7
7
|
import { resolveActorFrom } from '../auth/credentials.ts'
|
|
8
8
|
import type { CredentialDependencies } from '../auth/credentials.ts'
|
|
9
9
|
import { renderCustomFieldsForWire } from '../custom-fields/wire.ts'
|
|
10
|
-
import {
|
|
10
|
+
import { mountPipelineConvertRoute } from '../conversions/routes.ts'
|
|
11
|
+
import type { ConversionsService } from '../conversions/index.ts'
|
|
11
12
|
import type { CreateEnquiryInput, EnquiriesService, EnquiryView, UpdateEnquiryInput } from './service.ts'
|
|
12
13
|
|
|
13
14
|
/** Wire shapes for `/v1/enquiries`. Bodies are strict; an unknown field is a 422, per `api.md`. */
|
|
@@ -52,6 +53,7 @@ export const updateBody = z.strictObject(enquiryShape).partial()
|
|
|
52
53
|
|
|
53
54
|
export interface EnquiriesRoutesDependencies extends CredentialDependencies {
|
|
54
55
|
readonly service: EnquiriesService
|
|
56
|
+
readonly conversions: ConversionsService
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export function toCreateInput(body: z.infer<typeof createBody>): CreateEnquiryInput {
|
|
@@ -91,6 +93,7 @@ export function enquiryResponse(enquiry: EnquiryView): Record<string, unknown> {
|
|
|
91
93
|
company_id: enquiry.companyId,
|
|
92
94
|
owner_id: enquiry.ownerId,
|
|
93
95
|
converted_deal_id: enquiry.convertedDealId,
|
|
96
|
+
converted_to: convertedToResponse(enquiry.convertedTargetType, enquiry.convertedTargetId),
|
|
94
97
|
person_ids: enquiry.personIds,
|
|
95
98
|
summary: enquiry.summary,
|
|
96
99
|
tags: enquiry.tags,
|
|
@@ -156,17 +159,12 @@ export function mountEnquiriesRoutes(
|
|
|
156
159
|
})
|
|
157
160
|
|
|
158
161
|
/**
|
|
159
|
-
* Convert an enquiry to
|
|
160
|
-
*
|
|
161
|
-
* deal, wire-shaped, so the caller can navigate straight to it.
|
|
162
|
+
* Convert an enquiry to another pipeline record type. An empty body defaults
|
|
163
|
+
* the target to a deal for backward compatibility.
|
|
162
164
|
*/
|
|
163
|
-
router
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
168
|
-
const { workspaceId: _workspaceId, ...dealView } = deal
|
|
169
|
-
|
|
170
|
-
return context.json(dealResponse({ ...dealView, personIds }), 201)
|
|
165
|
+
mountPipelineConvertRoute(router, '/enquiries/:id/convert', {
|
|
166
|
+
...dependencies,
|
|
167
|
+
sourceKind: 'enquiry',
|
|
168
|
+
bodySchema: convertEnquiryBody,
|
|
171
169
|
})
|
|
172
170
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm'
|
|
2
|
+
import { check, index, jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { PIPELINE_KINDS } from '@kelpie/schemas'
|
|
1
4
|
import type { CustomFieldValue } from '@kelpie/schemas'
|
|
2
|
-
import { index, jsonb, pgTable, text } from 'drizzle-orm/pg-core'
|
|
3
5
|
|
|
4
|
-
import { createdAt, primaryId, searchVector, updatedAt } from '../../lib/columns.ts'
|
|
6
|
+
import { createdAt, oneOf, primaryId, searchVector, updatedAt } from '../../lib/columns.ts'
|
|
5
7
|
import type { SearchVectorPart } from '../../lib/columns.ts'
|
|
6
8
|
import { companies } from '../companies/schema.ts'
|
|
7
9
|
import { deals } from '../deals/schema.ts'
|
|
@@ -17,7 +19,8 @@ import { workspaceMembers, workspaces } from '../workspace/schema.ts'
|
|
|
17
19
|
* enquiry may arrive before a company is on file. `converted_deal_id` becomes
|
|
18
20
|
* non-null when the enquiry is converted via
|
|
19
21
|
* `POST /v1/enquiries/:id/convert`; deleting the deal nulls it back so a
|
|
20
|
-
* fresh conversion is possible.
|
|
22
|
+
* fresh conversion is possible. `converted_target_*` generalises that pointer
|
|
23
|
+
* to any pipeline type.
|
|
21
24
|
*/
|
|
22
25
|
export const enquiries = pgTable(
|
|
23
26
|
'enquiries',
|
|
@@ -34,6 +37,8 @@ export const enquiries = pgTable(
|
|
|
34
37
|
companyId: text('company_id').references(() => companies.id, { onDelete: 'restrict' }),
|
|
35
38
|
ownerId: text('owner_id').references(() => workspaceMembers.id, { onDelete: 'restrict' }),
|
|
36
39
|
convertedDealId: text('converted_deal_id').references(() => deals.id, { onDelete: 'set null' }),
|
|
40
|
+
convertedTargetType: text('converted_target_type'),
|
|
41
|
+
convertedTargetId: text('converted_target_id'),
|
|
37
42
|
summary: text('summary').notNull().default(''),
|
|
38
43
|
tags: text('tags').array().notNull().default([]),
|
|
39
44
|
// Workspace-defined fields, keyed by definition key. See people/schema.ts.
|
|
@@ -55,5 +60,9 @@ export const enquiries = pgTable(
|
|
|
55
60
|
index('enquiries_stage_idx').on(table.stageId),
|
|
56
61
|
index('enquiries_converted_deal_idx').on(table.convertedDealId),
|
|
57
62
|
index('enquiries_search_idx').using('gin', table.searchVector),
|
|
63
|
+
check(
|
|
64
|
+
'enquiries_converted_target_type_check',
|
|
65
|
+
sql`${table.convertedTargetType} is null or ${oneOf('enquiries_converted_target_type_check', table.convertedTargetType, PIPELINE_KINDS)}`,
|
|
66
|
+
),
|
|
58
67
|
],
|
|
59
68
|
)
|
|
@@ -9,9 +9,7 @@ import type { ListQueryParameters, Page } from '../../lib/pagination.ts'
|
|
|
9
9
|
import type { TransactionScope } from '../../runtime/transaction.ts'
|
|
10
10
|
import type { ActivityRecorder } from '../activities/recorder.ts'
|
|
11
11
|
import {
|
|
12
|
-
describeConversion,
|
|
13
12
|
describeCreation,
|
|
14
|
-
describeCreationFrom,
|
|
15
13
|
describeLink,
|
|
16
14
|
describeStageChange,
|
|
17
15
|
describeUnlink,
|
|
@@ -22,12 +20,10 @@ import { toEventActor } from '../../lib/actor.ts'
|
|
|
22
20
|
import type { Actor } from '../auth/actor.ts'
|
|
23
21
|
import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
|
|
24
22
|
import './events.ts'
|
|
25
|
-
import '../deals/events.ts'
|
|
26
23
|
import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
|
|
24
|
+
import { clearConversionPointersToTarget } from '../conversions/clearPointers.ts'
|
|
27
25
|
import * as companyRepository from '../companies/repository.ts'
|
|
28
26
|
import type { CustomFieldValuesValidator } from '../custom-fields/values.ts'
|
|
29
|
-
import * as dealRepository from '../deals/repository.ts'
|
|
30
|
-
import type { DealRecord } from '../deals/repository.ts'
|
|
31
27
|
import * as personLinks from '../personLinks.ts'
|
|
32
28
|
import * as pipelineRepository from '../pipelines/repository.ts'
|
|
33
29
|
import type { PipelineStageRecord } from '../pipelines/repository.ts'
|
|
@@ -108,12 +104,6 @@ export interface UpdateEnquiryInput {
|
|
|
108
104
|
readonly customFields?: Readonly<Record<string, CustomFieldWireValue | null>> | undefined
|
|
109
105
|
}
|
|
110
106
|
|
|
111
|
-
/** What `convertToDeal` returns: the freshly created deal, plus its people. */
|
|
112
|
-
export interface ConvertedDealView {
|
|
113
|
-
readonly deal: DealRecord
|
|
114
|
-
readonly personIds: readonly string[]
|
|
115
|
-
}
|
|
116
|
-
|
|
117
107
|
export interface EnquiriesService {
|
|
118
108
|
list(
|
|
119
109
|
actor: Actor,
|
|
@@ -124,7 +114,6 @@ export interface EnquiriesService {
|
|
|
124
114
|
create(actor: Actor, input: CreateEnquiryInput): Promise<EnquiryView>
|
|
125
115
|
update(actor: Actor, id: string, changes: UpdateEnquiryInput): Promise<EnquiryView>
|
|
126
116
|
remove(actor: Actor, id: string): Promise<void>
|
|
127
|
-
convertToDeal(actor: Actor, id: string): Promise<ConvertedDealView>
|
|
128
117
|
}
|
|
129
118
|
|
|
130
119
|
function toView(record: EnquiryRecord, personIds: readonly string[]): EnquiryView {
|
|
@@ -492,6 +481,8 @@ export function createEnquiriesService(dependencies: EnquiriesDependencies): Enq
|
|
|
492
481
|
await dependencies.transaction(async ({ tx, events }) => {
|
|
493
482
|
await require(workspaceId, id)
|
|
494
483
|
|
|
484
|
+
await clearConversionPointersToTarget(tx, workspaceId, 'enquiry', id)
|
|
485
|
+
|
|
495
486
|
// Notes, activities, decisions, plan items, person_links, list
|
|
496
487
|
// memberships and form_attach_targets rows are removed here in the
|
|
497
488
|
// same transaction. `form_submissions.enquiry_id` is a set-null FK, so
|
|
@@ -502,143 +493,5 @@ export function createEnquiriesService(dependencies: EnquiriesDependencies): Enq
|
|
|
502
493
|
events.emit('enquiries.enquiry.deleted', { type: 'enquiry', id }, {})
|
|
503
494
|
}, { workspaceId, actor: toEventActor(actor) })
|
|
504
495
|
},
|
|
505
|
-
|
|
506
|
-
async convertToDeal(actor, id) {
|
|
507
|
-
const workspaceId = requireWorkspaceId(actor)
|
|
508
|
-
const existing = await require(workspaceId, id)
|
|
509
|
-
|
|
510
|
-
if (existing.convertedDealId !== null) {
|
|
511
|
-
throw new AppError(
|
|
512
|
-
'conflict',
|
|
513
|
-
'This enquiry has already been converted to a deal',
|
|
514
|
-
[{ field: 'converted_deal_id', message: `Deal ${existing.convertedDealId}` }],
|
|
515
|
-
)
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (existing.companyId === null) {
|
|
519
|
-
throw AppError.validationFailed('An enquiry needs a company before it can become a deal', [
|
|
520
|
-
{ field: 'company_id', message: 'Link a company to the enquiry first' },
|
|
521
|
-
])
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const dealStages = await pipelineRepository.listStagesOfKind(
|
|
525
|
-
dependencies.db,
|
|
526
|
-
workspaceId,
|
|
527
|
-
'deal',
|
|
528
|
-
)
|
|
529
|
-
const openDealStage = dealStages.find((row) => row.open) ?? dealStages[0]
|
|
530
|
-
|
|
531
|
-
if (openDealStage === undefined) {
|
|
532
|
-
// Unreachable through the API: workspaces seed stages and the last
|
|
533
|
-
// deal stage cannot be removed.
|
|
534
|
-
throw AppError.conflict('This workspace has no deal stages')
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const enquiryStages = await pipelineRepository.listStagesOfKind(
|
|
538
|
-
dependencies.db,
|
|
539
|
-
workspaceId,
|
|
540
|
-
'enquiry',
|
|
541
|
-
)
|
|
542
|
-
// A closed enquiry stage is where a converted enquiry lands. If the
|
|
543
|
-
// workspace has deleted every closed stage we leave the enquiry where it
|
|
544
|
-
// is rather than refuse the conversion over board cosmetics.
|
|
545
|
-
const closedEnquiryStage = enquiryStages.find((row) => !row.open)
|
|
546
|
-
|
|
547
|
-
const personIds = await personLinks.listPersonIds(dependencies.db, workspaceId, {
|
|
548
|
-
targetType: 'enquiry',
|
|
549
|
-
targetId: id,
|
|
550
|
-
})
|
|
551
|
-
const dealId = dependencies.createId('deal')
|
|
552
|
-
const now = dependencies.now()
|
|
553
|
-
|
|
554
|
-
return dependencies.transaction(async ({ tx, events }) => {
|
|
555
|
-
const deal = await dealRepository.insertDeal(tx, {
|
|
556
|
-
id: dealId,
|
|
557
|
-
workspaceId,
|
|
558
|
-
name: existing.name,
|
|
559
|
-
companyId: existing.companyId as string,
|
|
560
|
-
stageId: openDealStage.id,
|
|
561
|
-
valueCents: null,
|
|
562
|
-
currency: null,
|
|
563
|
-
ownerId: existing.ownerId,
|
|
564
|
-
expectedClose: null,
|
|
565
|
-
competitors: [],
|
|
566
|
-
risks: '',
|
|
567
|
-
whyWin: '',
|
|
568
|
-
summary: existing.summary,
|
|
569
|
-
tags: [...existing.tags],
|
|
570
|
-
externalId: null,
|
|
571
|
-
customFields: {},
|
|
572
|
-
})
|
|
573
|
-
|
|
574
|
-
await personLinks.linkPeople(
|
|
575
|
-
tx,
|
|
576
|
-
dependencies.createId,
|
|
577
|
-
workspaceId,
|
|
578
|
-
{ targetType: 'deal', targetId: dealId },
|
|
579
|
-
personIds,
|
|
580
|
-
)
|
|
581
|
-
|
|
582
|
-
const stageChanged =
|
|
583
|
-
closedEnquiryStage !== undefined && closedEnquiryStage.id !== existing.stageId
|
|
584
|
-
const currentEnquiryStage = enquiryStages.find((row) => row.id === existing.stageId)
|
|
585
|
-
|
|
586
|
-
const updatedEnquiry = await repository.updateEnquiry(tx, workspaceId, id, {
|
|
587
|
-
convertedDealId: dealId,
|
|
588
|
-
...(stageChanged ? { stageId: closedEnquiryStage.id } : {}),
|
|
589
|
-
updatedAt: now,
|
|
590
|
-
})
|
|
591
|
-
|
|
592
|
-
if (updatedEnquiry === undefined) {
|
|
593
|
-
throw AppError.notFound('Enquiry not found')
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
await dependencies.recordActivity(tx, workspaceId, actor, {
|
|
597
|
-
targetType: 'deal',
|
|
598
|
-
targetId: dealId,
|
|
599
|
-
kind: 'created',
|
|
600
|
-
...describeCreationFrom('Deal', 'Enquiry', existing.name),
|
|
601
|
-
})
|
|
602
|
-
|
|
603
|
-
await dependencies.recordActivity(tx, workspaceId, actor, {
|
|
604
|
-
targetType: 'enquiry',
|
|
605
|
-
targetId: id,
|
|
606
|
-
kind: 'updated',
|
|
607
|
-
...describeConversion('Deal', deal.name),
|
|
608
|
-
})
|
|
609
|
-
|
|
610
|
-
if (stageChanged && currentEnquiryStage !== undefined) {
|
|
611
|
-
await dependencies.recordActivity(tx, workspaceId, actor, {
|
|
612
|
-
targetType: 'enquiry',
|
|
613
|
-
targetId: id,
|
|
614
|
-
kind: 'stage_changed',
|
|
615
|
-
...describeStageChange(currentEnquiryStage.label, closedEnquiryStage.label),
|
|
616
|
-
})
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
events.emit('deals.deal.created', { type: 'deal', id: dealId }, {})
|
|
620
|
-
events.emit(
|
|
621
|
-
'enquiries.enquiry.updated',
|
|
622
|
-
{ type: 'enquiry', id },
|
|
623
|
-
{
|
|
624
|
-
changed: stageChanged
|
|
625
|
-
? ['convertedDealId', 'stageId']
|
|
626
|
-
: ['convertedDealId'],
|
|
627
|
-
},
|
|
628
|
-
)
|
|
629
|
-
|
|
630
|
-
if (stageChanged && currentEnquiryStage !== undefined) {
|
|
631
|
-
events.emit(
|
|
632
|
-
'enquiries.enquiry.stage_changed',
|
|
633
|
-
{ type: 'enquiry', id },
|
|
634
|
-
{ fromStageId: currentEnquiryStage.id, toStageId: closedEnquiryStage.id },
|
|
635
|
-
)
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
events.emit('enquiries.enquiry.converted', { type: 'enquiry', id }, { dealId })
|
|
639
|
-
|
|
640
|
-
return { deal, personIds }
|
|
641
|
-
}, { workspaceId, actor: toEventActor(actor) })
|
|
642
|
-
},
|
|
643
496
|
}
|
|
644
497
|
}
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
termArg,
|
|
10
10
|
toSet,
|
|
11
11
|
} from '../crudTools.ts'
|
|
12
|
-
import {
|
|
12
|
+
import type { ConversionsService } from '../conversions/index.ts'
|
|
13
|
+
import { registerEnquiryConvertToDealTool, registerPipelineConvertTool } from '../conversions/mcp.ts'
|
|
13
14
|
import { createBody, enquiryResponse, toCreateInput, toUpdateInput, updateBody } from './routes.ts'
|
|
14
15
|
import type { EnquiriesService } from './service.ts'
|
|
15
16
|
|
|
@@ -24,7 +25,11 @@ const listArgs = z.strictObject({
|
|
|
24
25
|
person_id: idSetArg.optional().describe('Only enquiries any of these people are on.'),
|
|
25
26
|
})
|
|
26
27
|
|
|
27
|
-
export function registerEnquiriesTools(
|
|
28
|
+
export function registerEnquiriesTools(
|
|
29
|
+
mcp: McpToolRegistry,
|
|
30
|
+
service: EnquiriesService,
|
|
31
|
+
conversions: ConversionsService,
|
|
32
|
+
): void {
|
|
28
33
|
registerCrudTools(mcp, {
|
|
29
34
|
resource: 'enquiries',
|
|
30
35
|
subject: 'enquiry',
|
|
@@ -47,20 +52,6 @@ export function registerEnquiriesTools(mcp: McpToolRegistry, service: EnquiriesS
|
|
|
47
52
|
toUpdateInput,
|
|
48
53
|
})
|
|
49
54
|
|
|
50
|
-
mcp
|
|
51
|
-
|
|
52
|
-
description:
|
|
53
|
-
'Convert an enquiry to a Deal. Copies name, company, owner and linked ' +
|
|
54
|
-
'people to a new deal in the first open deal stage, moves the enquiry ' +
|
|
55
|
-
'to its first closed stage, and records the link on the enquiry. 409 if ' +
|
|
56
|
-
'the enquiry has already been converted; 422 if it has no company. ' +
|
|
57
|
-
'Mirrors POST /v1/enquiries/{id}/convert.',
|
|
58
|
-
inputSchema: z.strictObject({ id: idArg }),
|
|
59
|
-
invoke: async ({ id }, actor) => {
|
|
60
|
-
const { deal, personIds } = await service.convertToDeal(actor, id)
|
|
61
|
-
const { workspaceId: _workspaceId, ...dealView } = deal
|
|
62
|
-
|
|
63
|
-
return dealResponse({ ...dealView, personIds })
|
|
64
|
-
},
|
|
65
|
-
})
|
|
55
|
+
registerPipelineConvertTool(mcp, conversions, 'enquiry')
|
|
56
|
+
registerEnquiryConvertToDealTool(mcp, conversions)
|
|
66
57
|
}
|