@kelpie/server 0.10.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.
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +2 -0
- package/dist/app.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/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/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/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/meta/0038_snapshot.json +6554 -0
- package/migrations/meta/_journal.json +42 -0
- package/package.json +2 -2
- package/src/app.ts +3 -0
- package/src/lib/actor.ts +3 -1
- package/src/lib/apiKeyScopes.ts +213 -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/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/testing/fixtures.ts +1 -0
|
@@ -5,7 +5,7 @@ import type { ConsentPurposeStatus } from '@kelpie/schemas'
|
|
|
5
5
|
* owner may rename, reorder, or delete them, and add any others they need.
|
|
6
6
|
*
|
|
7
7
|
* Both starters default to `unknown` — silence about a person's wishes is not
|
|
8
|
-
* a grant, and every capture site (forms,
|
|
8
|
+
* a grant, and every capture site (forms, imports, manual override)
|
|
9
9
|
* writes an explicit `person_consents` row when consent is actually given.
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ export function registerConsentPurposesTools(
|
|
|
31
31
|
subject: 'consent purpose',
|
|
32
32
|
about:
|
|
33
33
|
'A workspace-defined consent purpose. Read these before writing a person ' +
|
|
34
|
-
'consent or setting a form/
|
|
34
|
+
'consent or setting a form/import purpose_id.',
|
|
35
35
|
service,
|
|
36
36
|
render: consentPurposeResponse,
|
|
37
37
|
listArgs,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { and, eq } from 'drizzle-orm'
|
|
2
|
+
import type { PipelineKind } from '@kelpie/schemas'
|
|
3
|
+
|
|
4
|
+
import type { Queryable } from '../../runtime/transaction.ts'
|
|
5
|
+
import { deals } from '../deals/schema.ts'
|
|
6
|
+
import { enquiries } from '../enquiries/schema.ts'
|
|
7
|
+
import { opportunities } from '../opportunities/schema.ts'
|
|
8
|
+
import { partnerships } from '../partnerships/schema.ts'
|
|
9
|
+
import { raises } from '../raises/schema.ts'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Clears `converted_target_*` on every pipeline record that pointed at a target
|
|
13
|
+
* being deleted. Enquiries also lose `converted_deal_id` when the target is a
|
|
14
|
+
* deal, matching the legacy FK `on delete set null` behaviour and allowing a
|
|
15
|
+
* fresh conversion once the created record is gone.
|
|
16
|
+
*/
|
|
17
|
+
export async function clearConversionPointersToTarget(
|
|
18
|
+
tx: Queryable,
|
|
19
|
+
workspaceId: string,
|
|
20
|
+
targetKind: PipelineKind,
|
|
21
|
+
targetId: string,
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
const match = and(
|
|
24
|
+
eq(deals.workspaceId, workspaceId),
|
|
25
|
+
eq(deals.convertedTargetType, targetKind),
|
|
26
|
+
eq(deals.convertedTargetId, targetId),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
await tx
|
|
30
|
+
.update(enquiries)
|
|
31
|
+
.set({
|
|
32
|
+
convertedTargetType: null,
|
|
33
|
+
convertedTargetId: null,
|
|
34
|
+
...(targetKind === 'deal' ? { convertedDealId: null } : {}),
|
|
35
|
+
})
|
|
36
|
+
.where(
|
|
37
|
+
and(
|
|
38
|
+
eq(enquiries.workspaceId, workspaceId),
|
|
39
|
+
eq(enquiries.convertedTargetType, targetKind),
|
|
40
|
+
eq(enquiries.convertedTargetId, targetId),
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
await tx
|
|
45
|
+
.update(deals)
|
|
46
|
+
.set({ convertedTargetType: null, convertedTargetId: null })
|
|
47
|
+
.where(match)
|
|
48
|
+
|
|
49
|
+
await tx
|
|
50
|
+
.update(opportunities)
|
|
51
|
+
.set({ convertedTargetType: null, convertedTargetId: null })
|
|
52
|
+
.where(
|
|
53
|
+
and(
|
|
54
|
+
eq(opportunities.workspaceId, workspaceId),
|
|
55
|
+
eq(opportunities.convertedTargetType, targetKind),
|
|
56
|
+
eq(opportunities.convertedTargetId, targetId),
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
await tx
|
|
61
|
+
.update(raises)
|
|
62
|
+
.set({ convertedTargetType: null, convertedTargetId: null })
|
|
63
|
+
.where(
|
|
64
|
+
and(
|
|
65
|
+
eq(raises.workspaceId, workspaceId),
|
|
66
|
+
eq(raises.convertedTargetType, targetKind),
|
|
67
|
+
eq(raises.convertedTargetId, targetId),
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
await tx
|
|
72
|
+
.update(partnerships)
|
|
73
|
+
.set({ convertedTargetType: null, convertedTargetId: null })
|
|
74
|
+
.where(
|
|
75
|
+
and(
|
|
76
|
+
eq(partnerships.workspaceId, workspaceId),
|
|
77
|
+
eq(partnerships.convertedTargetType, targetKind),
|
|
78
|
+
eq(partnerships.convertedTargetId, targetId),
|
|
79
|
+
),
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ModuleContext } from '../../runtime/module.ts'
|
|
2
|
+
import { createActivityRecorder } from '../activities/index.ts'
|
|
3
|
+
import { createCustomFieldValues } from '../custom-fields/index.ts'
|
|
4
|
+
import { createConversionsService } from './service.ts'
|
|
5
|
+
import type { ConversionsService } from './service.ts'
|
|
6
|
+
|
|
7
|
+
/** Build the shared conversion service from a module registration context. */
|
|
8
|
+
export function createConversionsFromContext(context: ModuleContext): ConversionsService {
|
|
9
|
+
return createConversionsService({
|
|
10
|
+
db: context.db,
|
|
11
|
+
transaction: context.transaction,
|
|
12
|
+
createId: context.createId,
|
|
13
|
+
now: context.now,
|
|
14
|
+
recordActivity: createActivityRecorder({
|
|
15
|
+
createId: context.createId,
|
|
16
|
+
now: context.now,
|
|
17
|
+
}),
|
|
18
|
+
customFields: createCustomFieldValues({ db: context.db }),
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import type { CustomFieldValue, CustomFieldWireValue, PipelineKind } from '@kelpie/schemas'
|
|
2
|
+
import { PIPELINE_KIND_LABELS } from '@kelpie/schemas'
|
|
3
|
+
import type { ConvertPipelineRecordInput } from '@kelpie/schemas'
|
|
4
|
+
|
|
5
|
+
import { AppError } from '../../lib/errors.ts'
|
|
6
|
+
import type { CustomFieldValuesValidator } from '../custom-fields/values.ts'
|
|
7
|
+
import * as dealRepository from '../deals/repository.ts'
|
|
8
|
+
import type { DealRecord } from '../deals/repository.ts'
|
|
9
|
+
import * as enquiryRepository from '../enquiries/repository.ts'
|
|
10
|
+
import type { EnquiryRecord } from '../enquiries/repository.ts'
|
|
11
|
+
import * as opportunityRepository from '../opportunities/repository.ts'
|
|
12
|
+
import type { OpportunityRecord } from '../opportunities/repository.ts'
|
|
13
|
+
import * as partnershipRepository from '../partnerships/repository.ts'
|
|
14
|
+
import type { PartnershipRecord } from '../partnerships/repository.ts'
|
|
15
|
+
import * as raiseRepository from '../raises/repository.ts'
|
|
16
|
+
import type { RaiseRecord } from '../raises/repository.ts'
|
|
17
|
+
import { definitionsForObject } from '../custom-fields/repository.ts'
|
|
18
|
+
|
|
19
|
+
/** Shared scalar fields every pipeline record carries. */
|
|
20
|
+
export interface PipelineSnapshot {
|
|
21
|
+
readonly kind: PipelineKind
|
|
22
|
+
readonly id: string
|
|
23
|
+
readonly name: string
|
|
24
|
+
readonly companyId: string | null
|
|
25
|
+
readonly ownerId: string | null
|
|
26
|
+
readonly summary: string
|
|
27
|
+
readonly tags: readonly string[]
|
|
28
|
+
readonly customFields: Readonly<Record<string, CustomFieldValue>>
|
|
29
|
+
readonly stageId: string
|
|
30
|
+
readonly convertedTargetType: string | null
|
|
31
|
+
readonly convertedTargetId: string | null
|
|
32
|
+
readonly convertedDealId: string | null
|
|
33
|
+
readonly source: string | null
|
|
34
|
+
readonly kindField: string | null
|
|
35
|
+
readonly expectedClose: string | null
|
|
36
|
+
readonly nextTouchpoint: string | null
|
|
37
|
+
readonly valueCents: number | null
|
|
38
|
+
readonly currency: string | null
|
|
39
|
+
readonly checkSizeCents: number | null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const COMPANY_REQUIRED_TARGETS = new Set<PipelineKind>(['deal', 'raise', 'partnership'])
|
|
43
|
+
|
|
44
|
+
export function objectLabelFor(kind: PipelineKind): string {
|
|
45
|
+
return PIPELINE_KIND_LABELS[kind]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function loadPipelineSnapshot(
|
|
49
|
+
db: Parameters<CustomFieldValuesValidator['forCreate']>[0],
|
|
50
|
+
workspaceId: string,
|
|
51
|
+
kind: PipelineKind,
|
|
52
|
+
id: string,
|
|
53
|
+
): Promise<PipelineSnapshot | undefined> {
|
|
54
|
+
switch (kind) {
|
|
55
|
+
case 'enquiry': {
|
|
56
|
+
const row = await enquiryRepository.findEnquiry(db, workspaceId, id)
|
|
57
|
+
|
|
58
|
+
if (row === undefined) {
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return snapshotFromEnquiry(row)
|
|
63
|
+
}
|
|
64
|
+
case 'deal': {
|
|
65
|
+
const row = await dealRepository.findDeal(db, workspaceId, id)
|
|
66
|
+
|
|
67
|
+
if (row === undefined) {
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return snapshotFromDeal(row)
|
|
72
|
+
}
|
|
73
|
+
case 'opportunity': {
|
|
74
|
+
const row = await opportunityRepository.findOpportunity(db, workspaceId, id)
|
|
75
|
+
|
|
76
|
+
if (row === undefined) {
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return snapshotFromOpportunity(row)
|
|
81
|
+
}
|
|
82
|
+
case 'raise': {
|
|
83
|
+
const row = await raiseRepository.findRaise(db, workspaceId, id)
|
|
84
|
+
|
|
85
|
+
if (row === undefined) {
|
|
86
|
+
return undefined
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return snapshotFromRaise(row)
|
|
90
|
+
}
|
|
91
|
+
case 'partnership': {
|
|
92
|
+
const row = await partnershipRepository.findPartnership(db, workspaceId, id)
|
|
93
|
+
|
|
94
|
+
if (row === undefined) {
|
|
95
|
+
return undefined
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return snapshotFromPartnership(row)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function snapshotFromEnquiry(row: EnquiryRecord): PipelineSnapshot {
|
|
104
|
+
return {
|
|
105
|
+
kind: 'enquiry',
|
|
106
|
+
id: row.id,
|
|
107
|
+
name: row.name,
|
|
108
|
+
companyId: row.companyId,
|
|
109
|
+
ownerId: row.ownerId,
|
|
110
|
+
summary: row.summary,
|
|
111
|
+
tags: row.tags,
|
|
112
|
+
customFields: row.customFields,
|
|
113
|
+
stageId: row.stageId,
|
|
114
|
+
convertedTargetType: row.convertedTargetType,
|
|
115
|
+
convertedTargetId: row.convertedTargetId,
|
|
116
|
+
convertedDealId: row.convertedDealId,
|
|
117
|
+
source: row.source,
|
|
118
|
+
kindField: null,
|
|
119
|
+
expectedClose: null,
|
|
120
|
+
nextTouchpoint: null,
|
|
121
|
+
valueCents: null,
|
|
122
|
+
currency: null,
|
|
123
|
+
checkSizeCents: null,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function snapshotFromDeal(row: DealRecord): PipelineSnapshot {
|
|
128
|
+
return {
|
|
129
|
+
kind: 'deal',
|
|
130
|
+
id: row.id,
|
|
131
|
+
name: row.name,
|
|
132
|
+
companyId: row.companyId,
|
|
133
|
+
ownerId: row.ownerId,
|
|
134
|
+
summary: row.summary,
|
|
135
|
+
tags: row.tags,
|
|
136
|
+
customFields: row.customFields,
|
|
137
|
+
stageId: row.stageId,
|
|
138
|
+
convertedTargetType: row.convertedTargetType,
|
|
139
|
+
convertedTargetId: row.convertedTargetId,
|
|
140
|
+
convertedDealId: null,
|
|
141
|
+
source: null,
|
|
142
|
+
kindField: null,
|
|
143
|
+
expectedClose: row.expectedClose,
|
|
144
|
+
nextTouchpoint: null,
|
|
145
|
+
valueCents: row.valueCents,
|
|
146
|
+
currency: row.currency,
|
|
147
|
+
checkSizeCents: null,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function snapshotFromOpportunity(row: OpportunityRecord): PipelineSnapshot {
|
|
152
|
+
return {
|
|
153
|
+
kind: 'opportunity',
|
|
154
|
+
id: row.id,
|
|
155
|
+
name: row.name,
|
|
156
|
+
companyId: row.companyId,
|
|
157
|
+
ownerId: row.ownerId,
|
|
158
|
+
summary: row.summary,
|
|
159
|
+
tags: row.tags,
|
|
160
|
+
customFields: row.customFields,
|
|
161
|
+
stageId: row.stageId,
|
|
162
|
+
convertedTargetType: row.convertedTargetType,
|
|
163
|
+
convertedTargetId: row.convertedTargetId,
|
|
164
|
+
convertedDealId: null,
|
|
165
|
+
source: null,
|
|
166
|
+
kindField: row.kind,
|
|
167
|
+
expectedClose: row.expectedClose,
|
|
168
|
+
nextTouchpoint: null,
|
|
169
|
+
valueCents: null,
|
|
170
|
+
currency: null,
|
|
171
|
+
checkSizeCents: null,
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function snapshotFromRaise(row: RaiseRecord): PipelineSnapshot {
|
|
176
|
+
return {
|
|
177
|
+
kind: 'raise',
|
|
178
|
+
id: row.id,
|
|
179
|
+
name: row.name,
|
|
180
|
+
companyId: row.companyId,
|
|
181
|
+
ownerId: row.ownerId,
|
|
182
|
+
summary: row.summary,
|
|
183
|
+
tags: row.tags,
|
|
184
|
+
customFields: row.customFields,
|
|
185
|
+
stageId: row.stageId,
|
|
186
|
+
convertedTargetType: row.convertedTargetType,
|
|
187
|
+
convertedTargetId: row.convertedTargetId,
|
|
188
|
+
convertedDealId: null,
|
|
189
|
+
source: null,
|
|
190
|
+
kindField: null,
|
|
191
|
+
expectedClose: row.expectedClose,
|
|
192
|
+
nextTouchpoint: null,
|
|
193
|
+
valueCents: null,
|
|
194
|
+
currency: row.currency,
|
|
195
|
+
checkSizeCents: row.checkSizeCents,
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function snapshotFromPartnership(row: PartnershipRecord): PipelineSnapshot {
|
|
200
|
+
return {
|
|
201
|
+
kind: 'partnership',
|
|
202
|
+
id: row.id,
|
|
203
|
+
name: row.name,
|
|
204
|
+
companyId: row.companyId,
|
|
205
|
+
ownerId: row.ownerId,
|
|
206
|
+
summary: row.summary,
|
|
207
|
+
tags: row.tags,
|
|
208
|
+
customFields: row.customFields,
|
|
209
|
+
stageId: row.stageId,
|
|
210
|
+
convertedTargetType: row.convertedTargetType,
|
|
211
|
+
convertedTargetId: row.convertedTargetId,
|
|
212
|
+
convertedDealId: null,
|
|
213
|
+
source: null,
|
|
214
|
+
kindField: row.kind,
|
|
215
|
+
expectedClose: null,
|
|
216
|
+
nextTouchpoint: row.nextTouchpoint,
|
|
217
|
+
valueCents: null,
|
|
218
|
+
currency: null,
|
|
219
|
+
checkSizeCents: null,
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function assertNotAlreadyConverted(source: PipelineSnapshot): void {
|
|
224
|
+
if (source.convertedTargetId !== null || source.convertedDealId !== null) {
|
|
225
|
+
const existingId = source.convertedTargetId ?? source.convertedDealId
|
|
226
|
+
|
|
227
|
+
throw new AppError(
|
|
228
|
+
'conflict',
|
|
229
|
+
'This record has already been converted',
|
|
230
|
+
[{ field: 'converted_to', message: existingId ?? 'unknown' }],
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function resolveCompanyId(
|
|
236
|
+
source: PipelineSnapshot,
|
|
237
|
+
targetKind: PipelineKind,
|
|
238
|
+
override: string | undefined,
|
|
239
|
+
): string | null {
|
|
240
|
+
const companyId = override ?? source.companyId
|
|
241
|
+
|
|
242
|
+
if (COMPANY_REQUIRED_TARGETS.has(targetKind) && companyId === null) {
|
|
243
|
+
throw AppError.validationFailed(
|
|
244
|
+
`A ${objectLabelFor(targetKind).toLowerCase()} needs a company before conversion`,
|
|
245
|
+
[{ field: 'company_id', message: 'Link a company to the record first, or send company_id' }],
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return companyId
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export async function intersectCustomFields(
|
|
253
|
+
tx: Parameters<CustomFieldValuesValidator['forCreate']>[0],
|
|
254
|
+
workspaceId: string,
|
|
255
|
+
targetKind: PipelineKind,
|
|
256
|
+
sourceCustomFields: Readonly<Record<string, CustomFieldValue>>,
|
|
257
|
+
customFields: CustomFieldValuesValidator,
|
|
258
|
+
): Promise<Readonly<Record<string, CustomFieldValue>>> {
|
|
259
|
+
const targetDefinitions = await definitionsForObject(tx, workspaceId, targetKind)
|
|
260
|
+
const targetKeys = new Set(targetDefinitions.map((definition) => definition.key))
|
|
261
|
+
const raw: Record<string, CustomFieldWireValue> = {}
|
|
262
|
+
|
|
263
|
+
for (const [key, value] of Object.entries(sourceCustomFields)) {
|
|
264
|
+
if (targetKeys.has(key)) {
|
|
265
|
+
raw[key] = value as CustomFieldWireValue
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return customFields.forCreate(tx, workspaceId, targetKind, raw)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface TargetInsertPayload {
|
|
273
|
+
readonly name: string
|
|
274
|
+
readonly companyId: string | null
|
|
275
|
+
readonly ownerId: string | null
|
|
276
|
+
readonly summary: string
|
|
277
|
+
readonly tags: readonly string[]
|
|
278
|
+
readonly customFields: Readonly<Record<string, CustomFieldValue>>
|
|
279
|
+
readonly stageId: string
|
|
280
|
+
readonly kindField: string
|
|
281
|
+
readonly expectedClose: string | null
|
|
282
|
+
readonly nextTouchpoint: string | null
|
|
283
|
+
readonly valueCents: number | null
|
|
284
|
+
readonly currency: string | null
|
|
285
|
+
readonly checkSizeCents: number | null
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function buildTargetInsertPayload(
|
|
289
|
+
source: PipelineSnapshot,
|
|
290
|
+
targetKind: PipelineKind,
|
|
291
|
+
body: ConvertPipelineRecordInput,
|
|
292
|
+
targetStageId: string,
|
|
293
|
+
): TargetInsertPayload {
|
|
294
|
+
const companyId = resolveCompanyId(source, targetKind, body.companyId)
|
|
295
|
+
const name = body.name ?? source.name
|
|
296
|
+
const kindField =
|
|
297
|
+
body.kind ??
|
|
298
|
+
(source.kindField !== null && (targetKind === 'opportunity' || targetKind === 'partnership')
|
|
299
|
+
? source.kindField
|
|
300
|
+
: '')
|
|
301
|
+
|
|
302
|
+
let expectedClose = source.expectedClose
|
|
303
|
+
let nextTouchpoint = source.nextTouchpoint
|
|
304
|
+
let valueCents = source.valueCents
|
|
305
|
+
let currency = source.currency
|
|
306
|
+
let checkSizeCents = source.checkSizeCents
|
|
307
|
+
|
|
308
|
+
if (targetKind === 'partnership') {
|
|
309
|
+
expectedClose = null
|
|
310
|
+
nextTouchpoint = source.expectedClose ?? source.nextTouchpoint
|
|
311
|
+
valueCents = null
|
|
312
|
+
checkSizeCents = null
|
|
313
|
+
} else if (targetKind === 'deal') {
|
|
314
|
+
nextTouchpoint = null
|
|
315
|
+
if (source.kind === 'raise') {
|
|
316
|
+
valueCents = source.checkSizeCents
|
|
317
|
+
checkSizeCents = null
|
|
318
|
+
}
|
|
319
|
+
} else if (targetKind === 'raise') {
|
|
320
|
+
nextTouchpoint = null
|
|
321
|
+
if (source.kind === 'deal') {
|
|
322
|
+
checkSizeCents = source.valueCents
|
|
323
|
+
valueCents = null
|
|
324
|
+
}
|
|
325
|
+
} else if (targetKind === 'opportunity' || targetKind === 'enquiry') {
|
|
326
|
+
nextTouchpoint = null
|
|
327
|
+
valueCents = null
|
|
328
|
+
checkSizeCents = null
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (targetKind !== 'deal' && targetKind !== 'opportunity' && targetKind !== 'raise') {
|
|
332
|
+
expectedClose = null
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (targetKind !== 'partnership') {
|
|
336
|
+
nextTouchpoint = null
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return {
|
|
340
|
+
name,
|
|
341
|
+
companyId,
|
|
342
|
+
ownerId: source.ownerId,
|
|
343
|
+
summary: source.summary,
|
|
344
|
+
tags: source.tags,
|
|
345
|
+
customFields: {},
|
|
346
|
+
stageId: body.stageId ?? targetStageId,
|
|
347
|
+
kindField,
|
|
348
|
+
expectedClose,
|
|
349
|
+
nextTouchpoint,
|
|
350
|
+
valueCents,
|
|
351
|
+
currency: currency ?? (targetKind === 'deal' || targetKind === 'raise' ? 'USD' : null),
|
|
352
|
+
checkSizeCents,
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export type ConvertedTargetRecord =
|
|
357
|
+
| DealRecord
|
|
358
|
+
| EnquiryRecord
|
|
359
|
+
| OpportunityRecord
|
|
360
|
+
| RaiseRecord
|
|
361
|
+
| PartnershipRecord
|
|
362
|
+
|
|
363
|
+
export async function insertConvertedTarget(
|
|
364
|
+
tx: Parameters<CustomFieldValuesValidator['forCreate']>[0],
|
|
365
|
+
workspaceId: string,
|
|
366
|
+
targetKind: PipelineKind,
|
|
367
|
+
targetId: string,
|
|
368
|
+
payload: TargetInsertPayload,
|
|
369
|
+
customFields: Readonly<Record<string, CustomFieldValue>>,
|
|
370
|
+
now: Date,
|
|
371
|
+
): Promise<ConvertedTargetRecord> {
|
|
372
|
+
switch (targetKind) {
|
|
373
|
+
case 'enquiry':
|
|
374
|
+
return enquiryRepository.insertEnquiry(tx, {
|
|
375
|
+
id: targetId,
|
|
376
|
+
workspaceId,
|
|
377
|
+
name: payload.name,
|
|
378
|
+
source: '',
|
|
379
|
+
stageId: payload.stageId,
|
|
380
|
+
companyId: payload.companyId,
|
|
381
|
+
ownerId: payload.ownerId,
|
|
382
|
+
convertedDealId: null,
|
|
383
|
+
convertedTargetType: null,
|
|
384
|
+
convertedTargetId: null,
|
|
385
|
+
summary: payload.summary,
|
|
386
|
+
tags: [...payload.tags],
|
|
387
|
+
customFields,
|
|
388
|
+
createdAt: now,
|
|
389
|
+
updatedAt: now,
|
|
390
|
+
})
|
|
391
|
+
case 'deal':
|
|
392
|
+
return dealRepository.insertDeal(tx, {
|
|
393
|
+
id: targetId,
|
|
394
|
+
workspaceId,
|
|
395
|
+
name: payload.name,
|
|
396
|
+
companyId: payload.companyId as string,
|
|
397
|
+
stageId: payload.stageId,
|
|
398
|
+
valueCents: payload.valueCents,
|
|
399
|
+
currency: payload.currency,
|
|
400
|
+
ownerId: payload.ownerId,
|
|
401
|
+
expectedClose: payload.expectedClose,
|
|
402
|
+
competitors: [],
|
|
403
|
+
risks: '',
|
|
404
|
+
whyWin: '',
|
|
405
|
+
summary: payload.summary,
|
|
406
|
+
tags: [...payload.tags],
|
|
407
|
+
externalId: null,
|
|
408
|
+
convertedTargetType: null,
|
|
409
|
+
convertedTargetId: null,
|
|
410
|
+
customFields,
|
|
411
|
+
})
|
|
412
|
+
case 'opportunity':
|
|
413
|
+
return opportunityRepository.insertOpportunity(tx, {
|
|
414
|
+
id: targetId,
|
|
415
|
+
workspaceId,
|
|
416
|
+
name: payload.name,
|
|
417
|
+
kind: payload.kindField,
|
|
418
|
+
stageId: payload.stageId,
|
|
419
|
+
companyId: payload.companyId,
|
|
420
|
+
ownerId: payload.ownerId,
|
|
421
|
+
expectedClose: payload.expectedClose,
|
|
422
|
+
summary: payload.summary,
|
|
423
|
+
tags: [...payload.tags],
|
|
424
|
+
convertedTargetType: null,
|
|
425
|
+
convertedTargetId: null,
|
|
426
|
+
customFields,
|
|
427
|
+
createdAt: now,
|
|
428
|
+
updatedAt: now,
|
|
429
|
+
})
|
|
430
|
+
case 'raise':
|
|
431
|
+
return raiseRepository.insertRaise(tx, {
|
|
432
|
+
id: targetId,
|
|
433
|
+
workspaceId,
|
|
434
|
+
name: payload.name,
|
|
435
|
+
companyId: payload.companyId as string,
|
|
436
|
+
stageId: payload.stageId,
|
|
437
|
+
checkSizeCents: payload.checkSizeCents,
|
|
438
|
+
currency: payload.currency,
|
|
439
|
+
thesisFit: '',
|
|
440
|
+
passReason: null,
|
|
441
|
+
ownerId: payload.ownerId,
|
|
442
|
+
expectedClose: payload.expectedClose,
|
|
443
|
+
summary: payload.summary,
|
|
444
|
+
tags: [...payload.tags],
|
|
445
|
+
convertedTargetType: null,
|
|
446
|
+
convertedTargetId: null,
|
|
447
|
+
customFields,
|
|
448
|
+
createdAt: now,
|
|
449
|
+
updatedAt: now,
|
|
450
|
+
})
|
|
451
|
+
case 'partnership':
|
|
452
|
+
return partnershipRepository.insertPartnership(tx, {
|
|
453
|
+
id: targetId,
|
|
454
|
+
workspaceId,
|
|
455
|
+
name: payload.name,
|
|
456
|
+
companyId: payload.companyId as string,
|
|
457
|
+
stageId: payload.stageId,
|
|
458
|
+
kind: payload.kindField,
|
|
459
|
+
nextTouchpoint: payload.nextTouchpoint,
|
|
460
|
+
ownerId: payload.ownerId,
|
|
461
|
+
goals: '',
|
|
462
|
+
successLooksLike: '',
|
|
463
|
+
summary: payload.summary,
|
|
464
|
+
tags: [...payload.tags],
|
|
465
|
+
convertedTargetType: null,
|
|
466
|
+
convertedTargetId: null,
|
|
467
|
+
customFields,
|
|
468
|
+
createdAt: now,
|
|
469
|
+
updatedAt: now,
|
|
470
|
+
})
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export async function markSourceConverted(
|
|
475
|
+
tx: Parameters<CustomFieldValuesValidator['forCreate']>[0],
|
|
476
|
+
workspaceId: string,
|
|
477
|
+
source: PipelineSnapshot,
|
|
478
|
+
targetKind: PipelineKind,
|
|
479
|
+
targetId: string,
|
|
480
|
+
closedStageId: string | undefined,
|
|
481
|
+
now: Date,
|
|
482
|
+
): Promise<void> {
|
|
483
|
+
const convertedChanges = {
|
|
484
|
+
convertedTargetType: targetKind,
|
|
485
|
+
convertedTargetId: targetId,
|
|
486
|
+
updatedAt: now,
|
|
487
|
+
...(source.kind === 'enquiry' && targetKind === 'deal' ? { convertedDealId: targetId } : {}),
|
|
488
|
+
...(closedStageId === undefined ? {} : { stageId: closedStageId }),
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
switch (source.kind) {
|
|
492
|
+
case 'enquiry': {
|
|
493
|
+
const updated = await enquiryRepository.updateEnquiry(tx, workspaceId, source.id, convertedChanges)
|
|
494
|
+
|
|
495
|
+
if (updated === undefined) {
|
|
496
|
+
throw AppError.notFound('Enquiry not found')
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return
|
|
500
|
+
}
|
|
501
|
+
case 'deal': {
|
|
502
|
+
const updated = await dealRepository.updateDeal(tx, workspaceId, source.id, convertedChanges)
|
|
503
|
+
|
|
504
|
+
if (updated === undefined) {
|
|
505
|
+
throw AppError.notFound('Deal not found')
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return
|
|
509
|
+
}
|
|
510
|
+
case 'opportunity': {
|
|
511
|
+
const updated = await opportunityRepository.updateOpportunity(
|
|
512
|
+
tx,
|
|
513
|
+
workspaceId,
|
|
514
|
+
source.id,
|
|
515
|
+
convertedChanges,
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
if (updated === undefined) {
|
|
519
|
+
throw AppError.notFound('Opportunity not found')
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return
|
|
523
|
+
}
|
|
524
|
+
case 'raise': {
|
|
525
|
+
const updated = await raiseRepository.updateRaise(tx, workspaceId, source.id, convertedChanges)
|
|
526
|
+
|
|
527
|
+
if (updated === undefined) {
|
|
528
|
+
throw AppError.notFound('Raise not found')
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return
|
|
532
|
+
}
|
|
533
|
+
case 'partnership': {
|
|
534
|
+
const updated = await partnershipRepository.updatePartnership(
|
|
535
|
+
tx,
|
|
536
|
+
workspaceId,
|
|
537
|
+
source.id,
|
|
538
|
+
convertedChanges,
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
if (updated === undefined) {
|
|
542
|
+
throw AppError.notFound('Partnership not found')
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createConversionsFromContext } from './factory.ts'
|
|
2
|
+
export { createConversionsService, createSharedConversionsService } from './service.ts'
|
|
3
|
+
export type { ConversionsDependencies, ConversionsService, ConvertPipelineRecordResult } from './service.ts'
|
|
4
|
+
export { repointRecordsAttachedTo } from './repoint.ts'
|
|
5
|
+
export { clearConversionPointersToTarget } from './clearPointers.ts'
|
|
6
|
+
export { objectLabelFor } from './fieldMap.ts'
|