@kelpie/server 0.5.2 → 0.6.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/README.md +5 -2
- package/dist/index.d.ts +17 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/actor.d.ts +9 -1
- package/dist/lib/actor.d.ts.map +1 -1
- package/dist/lib/actor.js +13 -0
- package/dist/lib/actor.js.map +1 -1
- package/dist/lib/config.d.ts +44 -6
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +9 -5
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/email.d.ts +15 -63
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +13 -65
- package/dist/lib/email.js.map +1 -1
- package/dist/lib/fromEnv.d.ts +60 -0
- package/dist/lib/fromEnv.d.ts.map +1 -0
- package/dist/lib/fromEnv.js +94 -0
- package/dist/lib/fromEnv.js.map +1 -0
- package/dist/lib/ids.d.ts +6 -0
- package/dist/lib/ids.d.ts.map +1 -1
- package/dist/lib/ids.js +6 -0
- package/dist/lib/ids.js.map +1 -1
- package/dist/lib/kelpieConfigFile.d.ts +123 -0
- package/dist/lib/kelpieConfigFile.d.ts.map +1 -0
- package/dist/lib/kelpieConfigFile.js +111 -0
- package/dist/lib/kelpieConfigFile.js.map +1 -0
- package/dist/lib/logger.d.ts +38 -7
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +58 -20
- package/dist/lib/logger.js.map +1 -1
- package/dist/modules/agent-tasks/index.d.ts.map +1 -1
- package/dist/modules/agent-tasks/index.js +4 -1
- package/dist/modules/agent-tasks/index.js.map +1 -1
- package/dist/modules/agent-tasks/prompt.d.ts +36 -6
- package/dist/modules/agent-tasks/prompt.d.ts.map +1 -1
- package/dist/modules/agent-tasks/prompt.js +33 -4
- package/dist/modules/agent-tasks/prompt.js.map +1 -1
- package/dist/modules/agent-tasks/service.d.ts.map +1 -1
- package/dist/modules/agent-tasks/service.js +3 -2
- package/dist/modules/agent-tasks/service.js.map +1 -1
- package/dist/modules/agent-tasks/wire.d.ts +11 -0
- package/dist/modules/agent-tasks/wire.d.ts.map +1 -1
- package/dist/modules/agent-tasks/wire.js +1 -0
- package/dist/modules/agent-tasks/wire.js.map +1 -1
- package/dist/modules/auth/index.d.ts.map +1 -1
- package/dist/modules/auth/index.js +8 -7
- package/dist/modules/auth/index.js.map +1 -1
- package/dist/modules/companies/events.d.ts +22 -0
- package/dist/modules/companies/events.d.ts.map +1 -0
- package/dist/modules/companies/events.js +8 -0
- package/dist/modules/companies/events.js.map +1 -0
- package/dist/modules/companies/index.d.ts.map +1 -1
- package/dist/modules/companies/index.js +2 -0
- package/dist/modules/companies/index.js.map +1 -1
- package/dist/modules/companies/service.d.ts +1 -0
- package/dist/modules/companies/service.d.ts.map +1 -1
- package/dist/modules/companies/service.js +8 -11
- package/dist/modules/companies/service.js.map +1 -1
- package/dist/modules/core.d.ts.map +1 -1
- package/dist/modules/core.js +4 -0
- package/dist/modules/core.js.map +1 -1
- package/dist/modules/deals/events.d.ts +31 -0
- package/dist/modules/deals/events.d.ts.map +1 -0
- package/dist/modules/deals/events.js +12 -0
- package/dist/modules/deals/events.js.map +1 -0
- package/dist/modules/deals/index.d.ts.map +1 -1
- package/dist/modules/deals/index.js +2 -0
- package/dist/modules/deals/index.js.map +1 -1
- package/dist/modules/deals/service.d.ts +1 -0
- package/dist/modules/deals/service.d.ts.map +1 -1
- package/dist/modules/deals/service.js +9 -18
- package/dist/modules/deals/service.js.map +1 -1
- package/dist/modules/decisions/events.d.ts +21 -0
- package/dist/modules/decisions/events.d.ts.map +1 -0
- package/dist/modules/decisions/events.js +11 -0
- package/dist/modules/decisions/events.js.map +1 -0
- package/dist/modules/decisions/index.d.ts.map +1 -1
- package/dist/modules/decisions/index.js +2 -0
- package/dist/modules/decisions/index.js.map +1 -1
- package/dist/modules/decisions/service.d.ts +1 -0
- package/dist/modules/decisions/service.d.ts.map +1 -1
- package/dist/modules/decisions/service.js +4 -7
- package/dist/modules/decisions/service.js.map +1 -1
- package/dist/modules/forms/events.d.ts +37 -0
- package/dist/modules/forms/events.d.ts.map +1 -0
- package/dist/modules/forms/events.js +15 -0
- package/dist/modules/forms/events.js.map +1 -0
- package/dist/modules/forms/index.d.ts.map +1 -1
- package/dist/modules/forms/index.js +2 -0
- package/dist/modules/forms/index.js.map +1 -1
- package/dist/modules/forms/service.d.ts +1 -0
- package/dist/modules/forms/service.d.ts.map +1 -1
- package/dist/modules/forms/service.js +8 -11
- package/dist/modules/forms/service.js.map +1 -1
- package/dist/modules/forms/submission.d.ts +5 -0
- package/dist/modules/forms/submission.d.ts.map +1 -1
- package/dist/modules/forms/submission.js +54 -28
- package/dist/modules/forms/submission.js.map +1 -1
- package/dist/modules/handbook/events.d.ts +28 -0
- package/dist/modules/handbook/events.d.ts.map +1 -0
- package/dist/modules/handbook/events.js +14 -0
- package/dist/modules/handbook/events.js.map +1 -0
- package/dist/modules/handbook/index.d.ts.map +1 -1
- package/dist/modules/handbook/index.js +2 -0
- package/dist/modules/handbook/index.js.map +1 -1
- package/dist/modules/handbook/service.d.ts +1 -0
- package/dist/modules/handbook/service.d.ts.map +1 -1
- package/dist/modules/handbook/service.js +8 -15
- package/dist/modules/handbook/service.js.map +1 -1
- package/dist/modules/hiring/candidates.d.ts +1 -0
- package/dist/modules/hiring/candidates.d.ts.map +1 -1
- package/dist/modules/hiring/candidates.js +8 -11
- package/dist/modules/hiring/candidates.js.map +1 -1
- package/dist/modules/hiring/events.d.ts +35 -0
- package/dist/modules/hiring/events.d.ts.map +1 -0
- package/dist/modules/hiring/events.js +11 -0
- package/dist/modules/hiring/events.js.map +1 -0
- package/dist/modules/hiring/index.d.ts.map +1 -1
- package/dist/modules/hiring/index.js +2 -0
- package/dist/modules/hiring/index.js.map +1 -1
- package/dist/modules/hiring/roles.d.ts +1 -0
- package/dist/modules/hiring/roles.d.ts.map +1 -1
- package/dist/modules/hiring/roles.js +8 -11
- package/dist/modules/hiring/roles.js.map +1 -1
- package/dist/modules/import-export/events.d.ts +22 -0
- package/dist/modules/import-export/events.d.ts.map +1 -0
- package/dist/modules/import-export/events.js +12 -0
- package/dist/modules/import-export/events.js.map +1 -0
- package/dist/modules/import-export/index.d.ts.map +1 -1
- package/dist/modules/import-export/index.js +2 -0
- package/dist/modules/import-export/index.js.map +1 -1
- package/dist/modules/import-export/service.d.ts +5 -0
- package/dist/modules/import-export/service.d.ts.map +1 -1
- package/dist/modules/import-export/service.js +53 -14
- package/dist/modules/import-export/service.js.map +1 -1
- package/dist/modules/notes/events.d.ts +22 -0
- package/dist/modules/notes/events.d.ts.map +1 -0
- package/dist/modules/notes/events.js +12 -0
- package/dist/modules/notes/events.js.map +1 -0
- package/dist/modules/notes/index.d.ts.map +1 -1
- package/dist/modules/notes/index.js +2 -0
- package/dist/modules/notes/index.js.map +1 -1
- package/dist/modules/notes/service.d.ts +1 -0
- package/dist/modules/notes/service.d.ts.map +1 -1
- package/dist/modules/notes/service.js +4 -7
- package/dist/modules/notes/service.js.map +1 -1
- package/dist/modules/opportunities/events.d.ts +31 -0
- package/dist/modules/opportunities/events.d.ts.map +1 -0
- package/dist/modules/opportunities/events.js +12 -0
- package/dist/modules/opportunities/events.js.map +1 -0
- package/dist/modules/opportunities/index.d.ts.map +1 -1
- package/dist/modules/opportunities/index.js +2 -0
- package/dist/modules/opportunities/index.js.map +1 -1
- package/dist/modules/opportunities/service.d.ts +1 -0
- package/dist/modules/opportunities/service.d.ts.map +1 -1
- package/dist/modules/opportunities/service.js +9 -18
- package/dist/modules/opportunities/service.js.map +1 -1
- package/dist/modules/partnerships/events.d.ts +31 -0
- package/dist/modules/partnerships/events.d.ts.map +1 -0
- package/dist/modules/partnerships/events.js +12 -0
- package/dist/modules/partnerships/events.js.map +1 -0
- package/dist/modules/partnerships/index.d.ts.map +1 -1
- package/dist/modules/partnerships/index.js +2 -0
- package/dist/modules/partnerships/index.js.map +1 -1
- package/dist/modules/partnerships/service.d.ts +1 -0
- package/dist/modules/partnerships/service.d.ts.map +1 -1
- package/dist/modules/partnerships/service.js +9 -18
- package/dist/modules/partnerships/service.js.map +1 -1
- package/dist/modules/people/events.d.ts +28 -0
- package/dist/modules/people/events.d.ts.map +1 -0
- package/dist/modules/people/events.js +18 -0
- package/dist/modules/people/events.js.map +1 -0
- package/dist/modules/people/index.d.ts.map +1 -1
- package/dist/modules/people/index.js +2 -0
- package/dist/modules/people/index.js.map +1 -1
- package/dist/modules/people/service.d.ts +1 -0
- package/dist/modules/people/service.d.ts.map +1 -1
- package/dist/modules/people/service.js +8 -11
- package/dist/modules/people/service.js.map +1 -1
- package/dist/modules/pipelines/service.d.ts +4 -0
- package/dist/modules/pipelines/service.d.ts.map +1 -1
- package/dist/modules/pipelines/service.js +31 -8
- package/dist/modules/pipelines/service.js.map +1 -1
- package/dist/modules/plans/events.d.ts +21 -0
- package/dist/modules/plans/events.d.ts.map +1 -0
- package/dist/modules/plans/events.js +11 -0
- package/dist/modules/plans/events.js.map +1 -0
- package/dist/modules/plans/index.d.ts.map +1 -1
- package/dist/modules/plans/index.js +2 -0
- package/dist/modules/plans/index.js.map +1 -1
- package/dist/modules/plans/service.d.ts +1 -0
- package/dist/modules/plans/service.d.ts.map +1 -1
- package/dist/modules/plans/service.js +6 -14
- package/dist/modules/plans/service.js.map +1 -1
- package/dist/modules/positions/events.d.ts +22 -0
- package/dist/modules/positions/events.d.ts.map +1 -0
- package/dist/modules/positions/events.js +8 -0
- package/dist/modules/positions/events.js.map +1 -0
- package/dist/modules/positions/index.d.ts.map +1 -1
- package/dist/modules/positions/index.js +2 -0
- package/dist/modules/positions/index.js.map +1 -1
- package/dist/modules/positions/service.d.ts +1 -0
- package/dist/modules/positions/service.d.ts.map +1 -1
- package/dist/modules/positions/service.js +8 -11
- package/dist/modules/positions/service.js.map +1 -1
- package/dist/modules/raises/events.d.ts +31 -0
- package/dist/modules/raises/events.d.ts.map +1 -0
- package/dist/modules/raises/events.js +12 -0
- package/dist/modules/raises/events.js.map +1 -0
- package/dist/modules/raises/index.d.ts.map +1 -1
- package/dist/modules/raises/index.js +2 -0
- package/dist/modules/raises/index.js.map +1 -1
- package/dist/modules/raises/service.d.ts +1 -0
- package/dist/modules/raises/service.d.ts.map +1 -1
- package/dist/modules/raises/service.js +9 -18
- package/dist/modules/raises/service.js.map +1 -1
- package/dist/modules/reseal.d.ts +55 -0
- package/dist/modules/reseal.d.ts.map +1 -1
- package/dist/modules/reseal.js +90 -1
- package/dist/modules/reseal.js.map +1 -1
- package/dist/modules/smtp-email/index.d.ts +69 -0
- package/dist/modules/smtp-email/index.d.ts.map +1 -0
- package/dist/modules/smtp-email/index.js +82 -0
- package/dist/modules/smtp-email/index.js.map +1 -0
- package/dist/modules/webhooks/index.d.ts.map +1 -1
- package/dist/modules/webhooks/index.js +5 -1
- package/dist/modules/webhooks/index.js.map +1 -1
- package/dist/modules/webhooks/payloads.d.ts +22 -7
- package/dist/modules/webhooks/payloads.d.ts.map +1 -1
- package/dist/modules/webhooks/payloads.js +63 -44
- package/dist/modules/webhooks/payloads.js.map +1 -1
- package/dist/modules/workspace/events.d.ts +52 -0
- package/dist/modules/workspace/events.d.ts.map +1 -0
- package/dist/modules/workspace/events.js +16 -0
- package/dist/modules/workspace/events.js.map +1 -0
- package/dist/modules/workspace/index.d.ts.map +1 -1
- package/dist/modules/workspace/index.js +6 -2
- package/dist/modules/workspace/index.js.map +1 -1
- package/dist/modules/workspace/service.d.ts +1 -0
- package/dist/modules/workspace/service.d.ts.map +1 -1
- package/dist/modules/workspace/service.js +13 -15
- package/dist/modules/workspace/service.js.map +1 -1
- package/dist/runtime/events.d.ts +86 -108
- package/dist/runtime/events.d.ts.map +1 -1
- package/dist/runtime/events.js +123 -52
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/module.d.ts +54 -2
- package/dist/runtime/module.d.ts.map +1 -1
- package/dist/runtime/registry.d.ts +23 -0
- package/dist/runtime/registry.d.ts.map +1 -1
- package/dist/runtime/registry.js +102 -2
- package/dist/runtime/registry.js.map +1 -1
- package/dist/runtime/transaction.d.ts +29 -4
- package/dist/runtime/transaction.d.ts.map +1 -1
- package/dist/runtime/transaction.js +48 -7
- package/dist/runtime/transaction.js.map +1 -1
- package/dist/testing/app.d.ts.map +1 -1
- package/dist/testing/app.js +11 -3
- package/dist/testing/app.js.map +1 -1
- package/dist/testing/database.d.ts.map +1 -1
- package/dist/testing/database.js +6 -3
- package/dist/testing/database.js.map +1 -1
- package/dist/testing/services.d.ts +21 -1
- package/dist/testing/services.d.ts.map +1 -1
- package/dist/testing/services.js +20 -5
- package/dist/testing/services.js.map +1 -1
- package/package.json +5 -2
- package/src/index.ts +44 -9
- package/src/lib/actor.ts +15 -1
- package/src/lib/config.ts +56 -7
- package/src/lib/email.ts +22 -92
- package/src/lib/fromEnv.ts +143 -0
- package/src/lib/ids.ts +6 -0
- package/src/lib/kelpieConfigFile.ts +283 -0
- package/src/lib/logger.ts +92 -34
- package/src/modules/agent-tasks/index.ts +4 -1
- package/src/modules/agent-tasks/prompt.ts +57 -9
- package/src/modules/agent-tasks/service.ts +3 -2
- package/src/modules/agent-tasks/wire.ts +12 -0
- package/src/modules/auth/index.ts +11 -9
- package/src/modules/companies/events.ts +25 -0
- package/src/modules/companies/index.ts +2 -0
- package/src/modules/companies/service.ts +8 -11
- package/src/modules/core.ts +4 -0
- package/src/modules/deals/events.ts +34 -0
- package/src/modules/deals/index.ts +2 -0
- package/src/modules/deals/service.ts +17 -18
- package/src/modules/decisions/events.ts +24 -0
- package/src/modules/decisions/index.ts +2 -0
- package/src/modules/decisions/service.ts +8 -7
- package/src/modules/forms/events.ts +37 -0
- package/src/modules/forms/index.ts +2 -0
- package/src/modules/forms/service.ts +12 -11
- package/src/modules/forms/submission.ts +80 -29
- package/src/modules/handbook/events.ts +31 -0
- package/src/modules/handbook/index.ts +2 -0
- package/src/modules/handbook/service.ts +8 -15
- package/src/modules/hiring/candidates.ts +8 -11
- package/src/modules/hiring/events.ts +36 -0
- package/src/modules/hiring/index.ts +2 -0
- package/src/modules/hiring/roles.ts +8 -11
- package/src/modules/import-export/events.ts +25 -0
- package/src/modules/import-export/index.ts +2 -0
- package/src/modules/import-export/service.ts +83 -15
- package/src/modules/notes/events.ts +25 -0
- package/src/modules/notes/index.ts +2 -0
- package/src/modules/notes/service.ts +8 -7
- package/src/modules/opportunities/events.ts +34 -0
- package/src/modules/opportunities/index.ts +2 -0
- package/src/modules/opportunities/service.ts +17 -18
- package/src/modules/partnerships/events.ts +34 -0
- package/src/modules/partnerships/index.ts +2 -0
- package/src/modules/partnerships/service.ts +17 -18
- package/src/modules/people/events.ts +36 -0
- package/src/modules/people/index.ts +2 -0
- package/src/modules/people/service.ts +97 -87
- package/src/modules/pipelines/service.ts +47 -8
- package/src/modules/plans/events.ts +24 -0
- package/src/modules/plans/index.ts +2 -0
- package/src/modules/plans/service.ts +14 -14
- package/src/modules/positions/events.ts +25 -0
- package/src/modules/positions/index.ts +2 -0
- package/src/modules/positions/service.ts +8 -11
- package/src/modules/raises/events.ts +34 -0
- package/src/modules/raises/index.ts +2 -0
- package/src/modules/raises/service.ts +17 -18
- package/src/modules/reseal.ts +144 -1
- package/src/modules/smtp-email/index.ts +119 -0
- package/src/modules/webhooks/index.ts +5 -1
- package/src/modules/webhooks/payloads.ts +94 -48
- package/src/modules/workspace/events.ts +46 -0
- package/src/modules/workspace/index.ts +6 -2
- package/src/modules/workspace/service.ts +37 -15
- package/src/runtime/events.ts +268 -107
- package/src/runtime/module.ts +55 -2
- package/src/runtime/registry.ts +169 -1
- package/src/runtime/transaction.ts +94 -17
- package/src/testing/app.ts +11 -3
- package/src/testing/database.ts +6 -3
- package/src/testing/services.ts +34 -5
|
@@ -10,8 +10,10 @@ import type { TransactionScope } from '../../runtime/transaction.ts'
|
|
|
10
10
|
import type { ActivityRecorder } from '../activities/recorder.ts'
|
|
11
11
|
import { describeCreation, describeUpdate } from '../activities/wording.ts'
|
|
12
12
|
import type { FieldLabels } from '../activities/wording.ts'
|
|
13
|
+
import { toEventActor } from '../../lib/actor.ts'
|
|
13
14
|
import type { Actor } from '../auth/actor.ts'
|
|
14
15
|
import { requireWorkspaceId } from '../auth/actor.ts'
|
|
16
|
+
import './events.ts'
|
|
15
17
|
import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
|
|
16
18
|
import { referencedElsewhere } from '../references.ts'
|
|
17
19
|
import * as repository from './repository.ts'
|
|
@@ -185,10 +187,10 @@ export function createCompaniesService(dependencies: CompaniesDependencies): Com
|
|
|
185
187
|
...describeCreation('Company'),
|
|
186
188
|
})
|
|
187
189
|
|
|
188
|
-
events.emit('
|
|
190
|
+
events.emit('companies.company.created', { type: 'company', id: created.id }, {})
|
|
189
191
|
|
|
190
192
|
return toView(created)
|
|
191
|
-
})
|
|
193
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
192
194
|
},
|
|
193
195
|
|
|
194
196
|
async update(actor, id, changes) {
|
|
@@ -228,15 +230,10 @@ export function createCompaniesService(dependencies: CompaniesDependencies): Com
|
|
|
228
230
|
...describeUpdate(changed, COMPANY_FIELD_LABELS, existing, columns),
|
|
229
231
|
})
|
|
230
232
|
|
|
231
|
-
events.emit('
|
|
232
|
-
workspaceId,
|
|
233
|
-
objectType: 'company',
|
|
234
|
-
recordId: id,
|
|
235
|
-
changedFields: changed,
|
|
236
|
-
})
|
|
233
|
+
events.emit('companies.company.updated', { type: 'company', id }, { changed })
|
|
237
234
|
|
|
238
235
|
return toView(updated)
|
|
239
|
-
})
|
|
236
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
240
237
|
},
|
|
241
238
|
|
|
242
239
|
async remove(actor, id) {
|
|
@@ -260,8 +257,8 @@ export function createCompaniesService(dependencies: CompaniesDependencies): Com
|
|
|
260
257
|
throw error
|
|
261
258
|
}
|
|
262
259
|
|
|
263
|
-
events.emit('
|
|
264
|
-
})
|
|
260
|
+
events.emit('companies.company.deleted', { type: 'company', id }, {})
|
|
261
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
265
262
|
},
|
|
266
263
|
}
|
|
267
264
|
}
|
package/src/modules/core.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { createPlansModule } from './plans/index.ts'
|
|
|
22
22
|
import { createPositionsModule } from './positions/index.ts'
|
|
23
23
|
import { createRaisesModule } from './raises/index.ts'
|
|
24
24
|
import { createSearchModule } from './search/index.ts'
|
|
25
|
+
import { createSmtpEmailModule } from './smtp-email/index.ts'
|
|
25
26
|
import { createWebhooksModule } from './webhooks/index.ts'
|
|
26
27
|
import { createWorkspaceModule } from './workspace/index.ts'
|
|
27
28
|
|
|
@@ -65,4 +66,7 @@ export const coreModules: readonly KelpieModule[] = [
|
|
|
65
66
|
createImportExportModule(coreMigrationsDirectory),
|
|
66
67
|
createAgentTasksModule(coreMigrationsDirectory),
|
|
67
68
|
createWebhooksModule(coreMigrationsDirectory),
|
|
69
|
+
// Owns no tables. Registers a `'smtp'` provider with core's email runtime;
|
|
70
|
+
// the factory only runs if the assembly's `email.provider` picks it.
|
|
71
|
+
createSmtpEmailModule(),
|
|
68
72
|
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { ModuleEventCatalog } from '../../runtime/module.ts'
|
|
4
|
+
|
|
5
|
+
/** Domain events published by the deals module. */
|
|
6
|
+
|
|
7
|
+
export const dealsEvents = {
|
|
8
|
+
'deals.deal.created': z.object({}).strict(),
|
|
9
|
+
'deals.deal.updated': z.object({ changed: z.array(z.string()).readonly() }),
|
|
10
|
+
'deals.deal.deleted': z.object({}).strict(),
|
|
11
|
+
'deals.deal.stage_changed': z.object({
|
|
12
|
+
fromStageId: z.string().nullable(),
|
|
13
|
+
toStageId: z.string(),
|
|
14
|
+
}),
|
|
15
|
+
} satisfies ModuleEventCatalog
|
|
16
|
+
|
|
17
|
+
export type DealCreatedData = Record<string, never>
|
|
18
|
+
export interface DealUpdatedData {
|
|
19
|
+
readonly changed: readonly string[]
|
|
20
|
+
}
|
|
21
|
+
export type DealDeletedData = Record<string, never>
|
|
22
|
+
export interface DealStageChangedData {
|
|
23
|
+
readonly fromStageId: string | null
|
|
24
|
+
readonly toStageId: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '../../runtime/events.ts' {
|
|
28
|
+
interface KelpieEventMap {
|
|
29
|
+
'deals.deal.created': DealCreatedData
|
|
30
|
+
'deals.deal.updated': DealUpdatedData
|
|
31
|
+
'deals.deal.deleted': DealDeletedData
|
|
32
|
+
'deals.deal.stage_changed': DealStageChangedData
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { KelpieModule } from '../../runtime/module.ts'
|
|
2
2
|
import { createActivityRecorder } from '../activities/index.ts'
|
|
3
|
+
import { dealsEvents } from './events.ts'
|
|
3
4
|
import { mountDealsRoutes } from './routes.ts'
|
|
4
5
|
import * as schema from './schema.ts'
|
|
5
6
|
import { createDealsService } from './service.ts'
|
|
@@ -17,6 +18,7 @@ export function createDealsModule(migrationsDirectory: string): KelpieModule {
|
|
|
17
18
|
return {
|
|
18
19
|
id: 'deals',
|
|
19
20
|
requires: ['companies', 'people', 'pipelines', 'activities'],
|
|
21
|
+
events: dealsEvents,
|
|
20
22
|
|
|
21
23
|
register(context) {
|
|
22
24
|
const service = createDealsService({
|
|
@@ -14,8 +14,10 @@ import {
|
|
|
14
14
|
describeUpdate,
|
|
15
15
|
} from '../activities/wording.ts'
|
|
16
16
|
import type { FieldLabels } from '../activities/wording.ts'
|
|
17
|
+
import { toEventActor } from '../../lib/actor.ts'
|
|
17
18
|
import type { Actor } from '../auth/actor.ts'
|
|
18
19
|
import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
|
|
20
|
+
import './events.ts'
|
|
19
21
|
import { deleteRecordsAttachedTo } from '../attachedRecords.ts'
|
|
20
22
|
import * as companyRepository from '../companies/repository.ts'
|
|
21
23
|
import * as pipelineRepository from '../pipelines/repository.ts'
|
|
@@ -297,10 +299,10 @@ export function createDealsService(dependencies: DealsDependencies): DealsServic
|
|
|
297
299
|
})
|
|
298
300
|
}
|
|
299
301
|
|
|
300
|
-
events.emit('
|
|
302
|
+
events.emit('deals.deal.created', { type: 'deal', id }, {})
|
|
301
303
|
|
|
302
304
|
return toView(created, personIds)
|
|
303
|
-
})
|
|
305
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
304
306
|
},
|
|
305
307
|
|
|
306
308
|
async update(actor, id, changes) {
|
|
@@ -393,25 +395,22 @@ export function createDealsService(dependencies: DealsDependencies): DealsServic
|
|
|
393
395
|
})
|
|
394
396
|
}
|
|
395
397
|
|
|
396
|
-
events.emit(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
})
|
|
398
|
+
events.emit(
|
|
399
|
+
'deals.deal.updated',
|
|
400
|
+
{ type: 'deal', id },
|
|
401
|
+
{ changed: linksChanged ? [...changed, 'personIds'] : changed },
|
|
402
|
+
)
|
|
402
403
|
|
|
403
404
|
if (stageMove !== undefined) {
|
|
404
|
-
events.emit(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
toStageId: stageMove.to.id,
|
|
410
|
-
})
|
|
405
|
+
events.emit(
|
|
406
|
+
'deals.deal.stage_changed',
|
|
407
|
+
{ type: 'deal', id },
|
|
408
|
+
{ fromStageId: stageMove.from.id, toStageId: stageMove.to.id },
|
|
409
|
+
)
|
|
411
410
|
}
|
|
412
411
|
|
|
413
412
|
return toView(updated, nextPeople ?? currentPeople)
|
|
414
|
-
})
|
|
413
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
415
414
|
},
|
|
416
415
|
|
|
417
416
|
async remove(actor, id) {
|
|
@@ -426,8 +425,8 @@ export function createDealsService(dependencies: DealsDependencies): DealsServic
|
|
|
426
425
|
await deleteRecordsAttachedTo(tx, workspaceId, 'deal', id)
|
|
427
426
|
await repository.deleteDeal(tx, workspaceId, id)
|
|
428
427
|
|
|
429
|
-
events.emit('
|
|
430
|
-
})
|
|
428
|
+
events.emit('deals.deal.deleted', { type: 'deal', id }, {})
|
|
429
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
431
430
|
},
|
|
432
431
|
}
|
|
433
432
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { ModuleEventCatalog } from '../../runtime/module.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Domain events published by the decisions module.
|
|
7
|
+
*
|
|
8
|
+
* `target` is the record the decision attaches to; the decision's own id lives
|
|
9
|
+
* in `data`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const decisionsEvents = {
|
|
13
|
+
'decisions.decision.added': z.object({ decisionId: z.string() }),
|
|
14
|
+
} satisfies ModuleEventCatalog
|
|
15
|
+
|
|
16
|
+
export interface DecisionAddedData {
|
|
17
|
+
readonly decisionId: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare module '../../runtime/events.ts' {
|
|
21
|
+
interface KelpieEventMap {
|
|
22
|
+
'decisions.decision.added': DecisionAddedData
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { KelpieModule } from '../../runtime/module.ts'
|
|
2
|
+
import { decisionsEvents } from './events.ts'
|
|
2
3
|
import { mountDecisionsRoutes } from './routes.ts'
|
|
3
4
|
import * as schema from './schema.ts'
|
|
4
5
|
import { createDecisionsService } from './service.ts'
|
|
@@ -17,6 +18,7 @@ export function createDecisionsModule(migrationsDirectory: string): KelpieModule
|
|
|
17
18
|
id: 'decisions',
|
|
18
19
|
requires: ['workspace'],
|
|
19
20
|
structural: true,
|
|
21
|
+
events: decisionsEvents,
|
|
20
22
|
|
|
21
23
|
register(context) {
|
|
22
24
|
const service = createDecisionsService({
|
|
@@ -5,8 +5,10 @@ import type { IdFactory } from '../../lib/ids.ts'
|
|
|
5
5
|
import { mapPage, readListWindow, toPage } from '../../lib/pagination.ts'
|
|
6
6
|
import type { ListQueryParameters, Page } from '../../lib/pagination.ts'
|
|
7
7
|
import type { TransactionScope } from '../../runtime/transaction.ts'
|
|
8
|
+
import { toEventActor } from '../../lib/actor.ts'
|
|
8
9
|
import type { Actor } from '../auth/actor.ts'
|
|
9
10
|
import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
|
|
11
|
+
import './events.ts'
|
|
10
12
|
import { targetExists } from '../recordTargets.ts'
|
|
11
13
|
import type { RecordTargetType } from '../recordTargets.ts'
|
|
12
14
|
import * as repository from './repository.ts'
|
|
@@ -158,15 +160,14 @@ export function createDecisionsService(dependencies: DecisionsDependencies): Dec
|
|
|
158
160
|
// decisions their own event, carrying the target, because a consumer
|
|
159
161
|
// watching a record wants the commitment without a second lookup to
|
|
160
162
|
// find out what it is attached to.
|
|
161
|
-
events.emit(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
})
|
|
163
|
+
events.emit(
|
|
164
|
+
'decisions.decision.added',
|
|
165
|
+
{ type: created.targetType, id: created.targetId },
|
|
166
|
+
{ decisionId: created.id },
|
|
167
|
+
)
|
|
167
168
|
|
|
168
169
|
return toView(created)
|
|
169
|
-
})
|
|
170
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
170
171
|
},
|
|
171
172
|
|
|
172
173
|
async update(actor, id, changes) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { ModuleEventCatalog } from '../../runtime/module.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Domain events published by the forms module.
|
|
7
|
+
*
|
|
8
|
+
* `forms.form.*` cover the form definition CRUD. `forms.submission.submitted`
|
|
9
|
+
* fires once per submission; the webhooks bridge translates it to the wire
|
|
10
|
+
* `form.submitted` event (the ids live in `data`).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const formsEvents = {
|
|
14
|
+
'forms.form.created': z.object({}).strict(),
|
|
15
|
+
'forms.form.updated': z.object({ changed: z.array(z.string()).readonly() }),
|
|
16
|
+
'forms.form.deleted': z.object({}).strict(),
|
|
17
|
+
'forms.submission.submitted': z.object({ formId: z.string(), submissionId: z.string() }),
|
|
18
|
+
} satisfies ModuleEventCatalog
|
|
19
|
+
|
|
20
|
+
export type FormCreatedData = Record<string, never>
|
|
21
|
+
export interface FormUpdatedData {
|
|
22
|
+
readonly changed: readonly string[]
|
|
23
|
+
}
|
|
24
|
+
export type FormDeletedData = Record<string, never>
|
|
25
|
+
export interface FormSubmissionData {
|
|
26
|
+
readonly formId: string
|
|
27
|
+
readonly submissionId: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare module '../../runtime/events.ts' {
|
|
31
|
+
interface KelpieEventMap {
|
|
32
|
+
'forms.form.created': FormCreatedData
|
|
33
|
+
'forms.form.updated': FormUpdatedData
|
|
34
|
+
'forms.form.deleted': FormDeletedData
|
|
35
|
+
'forms.submission.submitted': FormSubmissionData
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { KelpieModule } from '../../runtime/module.ts'
|
|
2
2
|
import { createActivityRecorder } from '../activities/index.ts'
|
|
3
|
+
import { formsEvents } from './events.ts'
|
|
3
4
|
import { mountPublicFormRoutes } from './publicRoutes.ts'
|
|
4
5
|
import { mountFormsRoutes } from './routes.ts'
|
|
5
6
|
import * as schema from './schema.ts'
|
|
@@ -23,6 +24,7 @@ export function createFormsModule(migrationsDirectory: string): KelpieModule {
|
|
|
23
24
|
return {
|
|
24
25
|
id: 'forms',
|
|
25
26
|
requires: ['people', 'companies', 'positions', 'pipelines', 'deals', 'activities'],
|
|
27
|
+
events: formsEvents,
|
|
26
28
|
|
|
27
29
|
register(context) {
|
|
28
30
|
const service = createFormsService({
|
|
@@ -6,8 +6,10 @@ import { mapPage, readListWindow, toPage } from '../../lib/pagination.ts'
|
|
|
6
6
|
import type { ListQueryParameters, Page } from '../../lib/pagination.ts'
|
|
7
7
|
import { generateToken } from '../../lib/tokens.ts'
|
|
8
8
|
import type { Transaction, TransactionScope } from '../../runtime/transaction.ts'
|
|
9
|
+
import { toEventActor } from '../../lib/actor.ts'
|
|
9
10
|
import type { Actor } from '../auth/actor.ts'
|
|
10
11
|
import { requireWorkspaceId } from '../auth/actor.ts'
|
|
12
|
+
import './events.ts'
|
|
11
13
|
import * as pipelineRepository from '../pipelines/repository.ts'
|
|
12
14
|
import { fieldsDiffer, findFieldProblems, storedOptions } from './fields.ts'
|
|
13
15
|
import type { FieldDraft, FieldShape } from './fields.ts'
|
|
@@ -253,10 +255,10 @@ export function createFormsService(dependencies: FormsDependencies): FormsServic
|
|
|
253
255
|
})
|
|
254
256
|
const fields = await writeFields(tx, workspaceId, id, input.fields)
|
|
255
257
|
|
|
256
|
-
events.emit('
|
|
258
|
+
events.emit('forms.form.created', { type: 'form', id }, {})
|
|
257
259
|
|
|
258
260
|
return toView(created, fields)
|
|
259
|
-
})
|
|
261
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
260
262
|
},
|
|
261
263
|
|
|
262
264
|
async update(actor, id, changes) {
|
|
@@ -310,15 +312,14 @@ export function createFormsService(dependencies: FormsDependencies): FormsServic
|
|
|
310
312
|
return writeFields(tx, workspaceId, id, changes.fields)
|
|
311
313
|
})()
|
|
312
314
|
|
|
313
|
-
events.emit(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
})
|
|
315
|
+
events.emit(
|
|
316
|
+
'forms.form.updated',
|
|
317
|
+
{ type: 'form', id },
|
|
318
|
+
{ changed: rewritesFields ? [...written, 'fields'] : written },
|
|
319
|
+
)
|
|
319
320
|
|
|
320
321
|
return toView(updated, fields)
|
|
321
|
-
})
|
|
322
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
322
323
|
},
|
|
323
324
|
|
|
324
325
|
/**
|
|
@@ -339,8 +340,8 @@ export function createFormsService(dependencies: FormsDependencies): FormsServic
|
|
|
339
340
|
throw AppError.notFound('Form not found')
|
|
340
341
|
}
|
|
341
342
|
|
|
342
|
-
events.emit('
|
|
343
|
-
})
|
|
343
|
+
events.emit('forms.form.deleted', { type: 'form', id }, {})
|
|
344
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
344
345
|
},
|
|
345
346
|
|
|
346
347
|
async listSubmissions(actor, formId, query) {
|
|
@@ -7,14 +7,19 @@ import { moduleCapabilityName } from '../../runtime/moduleConfig.ts'
|
|
|
7
7
|
import type { BufferedEvents, Transaction, TransactionScope } from '../../runtime/transaction.ts'
|
|
8
8
|
import type { ActivityRecorder, SystemActor } from '../activities/recorder.ts'
|
|
9
9
|
import { describeCreationVia, describeFormSubmission } from '../activities/wording.ts'
|
|
10
|
+
import '../companies/events.ts'
|
|
10
11
|
import * as companyRepository from '../companies/repository.ts'
|
|
11
12
|
import type { CompanyRecord } from '../companies/repository.ts'
|
|
12
13
|
import * as dealRepository from '../deals/repository.ts'
|
|
14
|
+
import '../deals/events.ts'
|
|
15
|
+
import '../people/events.ts'
|
|
13
16
|
import * as peopleRepository from '../people/repository.ts'
|
|
14
17
|
import type { PersonRecord } from '../people/repository.ts'
|
|
15
18
|
import * as pipelineRepository from '../pipelines/repository.ts'
|
|
19
|
+
import '../positions/events.ts'
|
|
16
20
|
import * as positionRepository from '../positions/repository.ts'
|
|
17
21
|
import * as workspaceRepository from '../workspace/repository.ts'
|
|
22
|
+
import './events.ts'
|
|
18
23
|
import {
|
|
19
24
|
DEAL_CLOSE_HORIZON_DAYS,
|
|
20
25
|
companyNameFrom,
|
|
@@ -148,34 +153,80 @@ function emitRecordEvents(
|
|
|
148
153
|
workspaceId: string,
|
|
149
154
|
touched: TouchedRecords,
|
|
150
155
|
): void {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
156
|
+
if (touched.person !== undefined) {
|
|
157
|
+
emitUpsertEvent(events, 'person', touched.person)
|
|
158
|
+
}
|
|
159
|
+
if (touched.company !== undefined) {
|
|
160
|
+
emitUpsertEvent(events, 'company', touched.company)
|
|
161
|
+
}
|
|
162
|
+
if (touched.position !== undefined) {
|
|
163
|
+
emitUpsertEvent(events, 'position', touched.position)
|
|
164
|
+
}
|
|
161
165
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
if (touched.dealId !== null) {
|
|
167
|
+
events.emit('deals.deal.created', { type: 'deal', id: touched.dealId }, {})
|
|
168
|
+
}
|
|
169
|
+
// workspaceId is used by the transaction scope's envelope stamping; the
|
|
170
|
+
// parameter stays on the signature so future call sites keep the same shape.
|
|
171
|
+
void workspaceId
|
|
172
|
+
}
|
|
166
173
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Dispatches the created/updated event owned by the record's module for one
|
|
176
|
+
* upsert. Split from the loop above so TypeScript can correlate the object
|
|
177
|
+
* type with its typed event name at each call site.
|
|
178
|
+
*/
|
|
179
|
+
function emitUpsertEvent(
|
|
180
|
+
events: BufferedEvents,
|
|
181
|
+
objectType: 'person' | 'company' | 'position',
|
|
182
|
+
outcome: { readonly created: boolean; readonly record: { readonly id: string }; readonly filled: readonly string[] },
|
|
183
|
+
): void {
|
|
184
|
+
if (outcome.created) {
|
|
185
|
+
switch (objectType) {
|
|
186
|
+
case 'person':
|
|
187
|
+
events.emit('people.person.created', { type: 'person', id: outcome.record.id }, {})
|
|
188
|
+
return
|
|
189
|
+
case 'company':
|
|
190
|
+
events.emit('companies.company.created', { type: 'company', id: outcome.record.id }, {})
|
|
191
|
+
return
|
|
192
|
+
case 'position':
|
|
193
|
+
events.emit(
|
|
194
|
+
'positions.position.created',
|
|
195
|
+
{ type: 'position', id: outcome.record.id },
|
|
196
|
+
{},
|
|
197
|
+
)
|
|
198
|
+
return
|
|
174
199
|
}
|
|
175
200
|
}
|
|
176
201
|
|
|
177
|
-
if (
|
|
178
|
-
|
|
202
|
+
if (outcome.filled.length === 0) {
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const changed = outcome.filled
|
|
207
|
+
|
|
208
|
+
switch (objectType) {
|
|
209
|
+
case 'person':
|
|
210
|
+
events.emit(
|
|
211
|
+
'people.person.updated',
|
|
212
|
+
{ type: 'person', id: outcome.record.id },
|
|
213
|
+
{ changed },
|
|
214
|
+
)
|
|
215
|
+
return
|
|
216
|
+
case 'company':
|
|
217
|
+
events.emit(
|
|
218
|
+
'companies.company.updated',
|
|
219
|
+
{ type: 'company', id: outcome.record.id },
|
|
220
|
+
{ changed },
|
|
221
|
+
)
|
|
222
|
+
return
|
|
223
|
+
case 'position':
|
|
224
|
+
events.emit(
|
|
225
|
+
'positions.position.updated',
|
|
226
|
+
{ type: 'position', id: outcome.record.id },
|
|
227
|
+
{ changed },
|
|
228
|
+
)
|
|
229
|
+
return
|
|
179
230
|
}
|
|
180
231
|
}
|
|
181
232
|
|
|
@@ -484,11 +535,11 @@ export function createFormSubmitService(dependencies: SubmissionDependencies): F
|
|
|
484
535
|
}
|
|
485
536
|
|
|
486
537
|
emitRecordEvents(events, workspaceId, { person, company, position, dealId })
|
|
487
|
-
events.emit(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
submissionId: submission.id,
|
|
491
|
-
|
|
538
|
+
events.emit(
|
|
539
|
+
'forms.submission.submitted',
|
|
540
|
+
{ type: 'submission', id: submission.id },
|
|
541
|
+
{ formId: form.id, submissionId: submission.id },
|
|
542
|
+
)
|
|
492
543
|
|
|
493
544
|
return {
|
|
494
545
|
submissionId: submission.id,
|
|
@@ -500,7 +551,7 @@ export function createFormSubmitService(dependencies: SubmissionDependencies): F
|
|
|
500
551
|
submittedAt: submission.submittedAt,
|
|
501
552
|
thankYouMessage: form.thankYouMessage,
|
|
502
553
|
}
|
|
503
|
-
})
|
|
554
|
+
}, { workspaceId })
|
|
504
555
|
},
|
|
505
556
|
}
|
|
506
557
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { ModuleEventCatalog } from '../../runtime/module.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Domain events published by the handbook module.
|
|
7
|
+
*
|
|
8
|
+
* Handbook pages are content objects, not CRM records — the target type is
|
|
9
|
+
* `handbook_page`, and the webhooks bridge does not (yet) deliver these to
|
|
10
|
+
* subscribers. They still fire on the bus for in-process consumers.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const handbookEvents = {
|
|
14
|
+
'handbook.page.created': z.object({}).strict(),
|
|
15
|
+
'handbook.page.updated': z.object({ changed: z.array(z.string()).readonly() }),
|
|
16
|
+
'handbook.page.deleted': z.object({}).strict(),
|
|
17
|
+
} satisfies ModuleEventCatalog
|
|
18
|
+
|
|
19
|
+
export type HandbookPageCreatedData = Record<string, never>
|
|
20
|
+
export interface HandbookPageUpdatedData {
|
|
21
|
+
readonly changed: readonly string[]
|
|
22
|
+
}
|
|
23
|
+
export type HandbookPageDeletedData = Record<string, never>
|
|
24
|
+
|
|
25
|
+
declare module '../../runtime/events.ts' {
|
|
26
|
+
interface KelpieEventMap {
|
|
27
|
+
'handbook.page.created': HandbookPageCreatedData
|
|
28
|
+
'handbook.page.updated': HandbookPageUpdatedData
|
|
29
|
+
'handbook.page.deleted': HandbookPageDeletedData
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { KelpieModule } from '../../runtime/module.ts'
|
|
2
|
+
import { handbookEvents } from './events.ts'
|
|
2
3
|
import { mountHandbookRoutes } from './routes.ts'
|
|
3
4
|
import * as schema from './schema.ts'
|
|
4
5
|
import { createHandbookService } from './service.ts'
|
|
@@ -20,6 +21,7 @@ export function createHandbookModule(migrationsDirectory: string): KelpieModule
|
|
|
20
21
|
return {
|
|
21
22
|
id: 'handbook',
|
|
22
23
|
requires: ['workspace'],
|
|
24
|
+
events: handbookEvents,
|
|
23
25
|
|
|
24
26
|
register(context) {
|
|
25
27
|
const service = createHandbookService({
|
|
@@ -6,8 +6,10 @@ import type { IdFactory } from '../../lib/ids.ts'
|
|
|
6
6
|
import { mapPage, readListWindow, toPage } from '../../lib/pagination.ts'
|
|
7
7
|
import type { ListQueryParameters, Page } from '../../lib/pagination.ts'
|
|
8
8
|
import type { Transaction, TransactionScope } from '../../runtime/transaction.ts'
|
|
9
|
+
import { toEventActor } from '../../lib/actor.ts'
|
|
9
10
|
import type { Actor } from '../auth/actor.ts'
|
|
10
11
|
import { actorMemberId, requireWorkspaceId } from '../auth/actor.ts'
|
|
12
|
+
import './events.ts'
|
|
11
13
|
import * as repository from './repository.ts'
|
|
12
14
|
import { DEFAULT_HANDBOOK_PAGE_SORT, HANDBOOK_PAGE_SORTS } from './repository.ts'
|
|
13
15
|
import type { HandbookPageFilters, HandbookPageRecord } from './repository.ts'
|
|
@@ -292,11 +294,7 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
|
|
|
292
294
|
updatedBy: actorMemberId(actor),
|
|
293
295
|
})
|
|
294
296
|
|
|
295
|
-
events.emit('
|
|
296
|
-
workspaceId,
|
|
297
|
-
objectType: 'handbook_page',
|
|
298
|
-
recordId: id,
|
|
299
|
-
})
|
|
297
|
+
events.emit('handbook.page.created', { type: 'handbook_page', id }, {})
|
|
300
298
|
|
|
301
299
|
return toView(created)
|
|
302
300
|
} catch (error: unknown) {
|
|
@@ -308,7 +306,7 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
|
|
|
308
306
|
|
|
309
307
|
throw error
|
|
310
308
|
}
|
|
311
|
-
})
|
|
309
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
312
310
|
},
|
|
313
311
|
|
|
314
312
|
async update(actor, id, changes) {
|
|
@@ -346,16 +344,11 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
|
|
|
346
344
|
const changed = [...written, ...movedFields]
|
|
347
345
|
|
|
348
346
|
if (changed.length > 0) {
|
|
349
|
-
events.emit('
|
|
350
|
-
workspaceId,
|
|
351
|
-
objectType: 'handbook_page',
|
|
352
|
-
recordId: id,
|
|
353
|
-
changedFields: changed,
|
|
354
|
-
})
|
|
347
|
+
events.emit('handbook.page.updated', { type: 'handbook_page', id }, { changed })
|
|
355
348
|
}
|
|
356
349
|
|
|
357
350
|
return toView(updated)
|
|
358
|
-
})
|
|
351
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
359
352
|
},
|
|
360
353
|
|
|
361
354
|
/**
|
|
@@ -391,9 +384,9 @@ export function createHandbookService(dependencies: HandbookDependencies): Handb
|
|
|
391
384
|
)
|
|
392
385
|
|
|
393
386
|
for (const recordId of removed) {
|
|
394
|
-
events.emit('
|
|
387
|
+
events.emit('handbook.page.deleted', { type: 'handbook_page', id: recordId }, {})
|
|
395
388
|
}
|
|
396
|
-
})
|
|
389
|
+
}, { workspaceId, actor: toEventActor(actor) })
|
|
397
390
|
},
|
|
398
391
|
}
|
|
399
392
|
}
|