@rytass/bpm-core-nestjs-module 0.3.0 → 0.5.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/CHANGELOG.md +44 -0
- package/eslint.config.mjs +20 -0
- package/jest.config.cts +15 -0
- package/package.json +2 -2
- package/project.json +58 -0
- package/src/lib/attachment/attachment-options.spec.ts +45 -0
- package/src/lib/attachment/attachment-options.ts +130 -0
- package/src/lib/attachment/attachment-storage.provider.spec.ts +79 -0
- package/src/lib/attachment/attachment-storage.provider.ts +60 -0
- package/src/lib/attachment/{attachment-storage.token.d.ts → attachment-storage.token.ts} +3 -1
- package/src/lib/attachment/attachment.controller.ts +39 -0
- package/src/lib/attachment/attachment.entity.ts +59 -0
- package/src/lib/attachment/attachment.module.ts +149 -0
- package/src/lib/attachment/attachment.mutations.ts +22 -0
- package/src/lib/attachment/attachment.queries.ts +65 -0
- package/src/lib/attachment/attachment.service.spec.ts +319 -0
- package/src/lib/attachment/attachment.service.ts +477 -0
- package/src/lib/attachment/dto/upload-attachment.input.ts +60 -0
- package/src/lib/bpm/bpm-root.module.spec.ts +138 -0
- package/src/lib/bpm/bpm-root.module.ts +320 -0
- package/src/lib/bpm-auth/bpm-auth-context.extractor.ts +106 -0
- package/src/lib/bpm-auth/bpm-auth-context.ts +40 -0
- package/src/lib/bpm-auth/bpm-auth.authorization.ts +80 -0
- package/src/lib/bpm-auth/bpm-auth.decorators.ts +19 -0
- package/src/lib/bpm-auth/bpm-auth.guard.ts +31 -0
- package/src/lib/bpm-auth/bpm-auth.module.spec.ts +106 -0
- package/src/lib/bpm-auth/bpm-auth.module.ts +69 -0
- package/src/lib/bpm-auth/bpm-auth.options.ts +21 -0
- package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.ts +55 -0
- package/src/lib/common/filters/all-exceptions.filter.ts +138 -0
- package/src/lib/common/iso-duration.ts +31 -0
- package/src/lib/condition/condition.module.ts +8 -0
- package/src/lib/condition/condition.service.spec.ts +50 -0
- package/src/lib/condition/condition.service.ts +141 -0
- package/src/lib/database/data-source.ts +7 -0
- package/src/lib/database/migration-runner.ts +26 -0
- package/src/lib/database/reconcile-legacy-migrations.ts +87 -0
- package/src/lib/database/typeorm.config.ts +217 -0
- package/src/lib/delegation/delegation-rule.entity.ts +84 -0
- package/src/lib/delegation/delegation.enums.ts +21 -0
- package/src/lib/delegation/delegation.module.ts +14 -0
- package/src/lib/delegation/delegation.mutations.ts +92 -0
- package/src/lib/delegation/delegation.queries.ts +111 -0
- package/src/lib/delegation/delegation.service.spec.ts +295 -0
- package/src/lib/delegation/delegation.service.ts +482 -0
- package/src/lib/delegation/dto/delegation-rule.input.ts +125 -0
- package/src/lib/form/dto/form-definition.input.ts +90 -0
- package/src/lib/form/form-definition-version.entity.ts +66 -0
- package/src/lib/form/form-definition.entity.ts +54 -0
- package/src/lib/form/form-schema-lint.object.ts +10 -0
- package/src/lib/form/form-schema.validator.spec.ts +180 -0
- package/src/lib/form/form-schema.validator.ts +538 -0
- package/src/lib/form/form.enums.ts +20 -0
- package/src/lib/form/form.module.ts +19 -0
- package/src/lib/form/form.mutations.ts +73 -0
- package/src/lib/form/form.queries.ts +72 -0
- package/src/lib/form/form.service.spec.ts +371 -0
- package/src/lib/form/form.service.ts +607 -0
- package/src/lib/identity/identity-options.ts +41 -0
- package/src/lib/identity/identity.module.ts +96 -0
- package/src/lib/identity/identity.queries.ts +61 -0
- package/src/lib/identity/identity.service.spec.ts +328 -0
- package/src/lib/identity/identity.service.ts +277 -0
- package/src/lib/identity/member-base.adapter.spec.ts +122 -0
- package/src/lib/identity/member-base.adapter.ts +302 -0
- package/src/lib/identity/member-metadata-cache.entity.ts +27 -0
- package/src/lib/identity/{member-not-found.exception.d.ts → member-not-found.exception.ts} +8 -3
- package/src/lib/identity/member-profile.object.ts +28 -0
- package/src/lib/identity/member-resolver.interface.ts +140 -0
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.ts +14 -0
- package/src/lib/migrations/{0000000001000-identity-organization-foundation.js → 0000000001000-identity-organization-foundation.ts} +38 -29
- package/src/lib/migrations/{0000000002000-form-builder-foundation.js → 0000000002000-form-builder-foundation.ts} +22 -21
- package/src/lib/migrations/{0000000003000-approval-template-foundation.js → 0000000003000-approval-template-foundation.ts} +24 -21
- package/src/lib/migrations/{0000000004000-workflow-engine-foundation.js → 0000000004000-workflow-engine-foundation.ts} +46 -34
- package/src/lib/migrations/{0000000005000-delegation-rules.js → 0000000005000-delegation-rules.ts} +20 -19
- package/src/lib/migrations/{0000000006000-notifications-sla.js → 0000000006000-notifications-sla.ts} +26 -23
- package/src/lib/migrations/{0000000007000-signatures-attachments.js → 0000000007000-signatures-attachments.ts} +28 -27
- package/src/lib/migrations/{0000000008000-approval-template-categories.js → 0000000008000-approval-template-categories.ts} +28 -25
- package/src/lib/migrations/{0000000009000-task-candidates.js → 0000000009000-task-candidates.ts} +26 -23
- package/src/lib/migrations/{0000000010000-notification-delivery-state.js → 0000000010000-notification-delivery-state.ts} +16 -17
- package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.ts +19 -0
- package/src/lib/migrations/0000000012000-notification-sla-idempotency.ts +22 -0
- package/src/lib/migrations/0000000013000-workflow-query-indexes.ts +113 -0
- package/src/lib/migrations/0000000014000-notification-resolution.ts +29 -0
- package/src/lib/migrations/{0000000015000-backfill-stale-notification-resolution.js → 0000000015000-backfill-stale-notification-resolution.ts} +15 -16
- package/src/lib/migrations/{0000000016000-archive-parallel-form-drafts.js → 0000000016000-archive-parallel-form-drafts.ts} +15 -16
- package/src/lib/migrations/{0000000017000-adhoc-directives.js → 0000000017000-adhoc-directives.ts} +18 -19
- package/src/lib/migrations/index.ts +59 -0
- package/src/lib/notification/dto/notification-preference.input.ts +46 -0
- package/src/lib/notification/notification-delivery-scheduler.service.ts +69 -0
- package/src/lib/notification/notification-delivery.service.spec.ts +315 -0
- package/src/lib/notification/notification-delivery.service.ts +339 -0
- package/src/lib/notification/notification-dispatcher.token.ts +13 -0
- package/src/lib/notification/notification-options.module.ts +67 -0
- package/src/lib/notification/notification-options.spec.ts +93 -0
- package/src/lib/notification/notification-options.ts +452 -0
- package/src/lib/notification/notification-preference.entity.ts +35 -0
- package/src/lib/notification/notification-sla-scheduler.service.ts +66 -0
- package/src/lib/notification/notification-template.spec.ts +33 -0
- package/src/lib/notification/notification-template.ts +97 -0
- package/src/lib/notification/notification.entity.ts +129 -0
- package/src/lib/notification/notification.enums.ts +64 -0
- package/src/lib/notification/notification.module.ts +37 -0
- package/src/lib/notification/notification.mutations.ts +47 -0
- package/src/lib/notification/notification.queries.ts +64 -0
- package/src/lib/notification/notification.service.spec.ts +412 -0
- package/src/lib/notification/notification.service.ts +1129 -0
- package/src/lib/organization/dto/manager-resolution.input.ts +91 -0
- package/src/lib/organization/dto/membership.input.ts +77 -0
- package/src/lib/organization/dto/org-unit.input.ts +96 -0
- package/src/lib/organization/dto/position.input.ts +50 -0
- package/src/lib/organization/json-metadata.ts +15 -0
- package/src/lib/organization/manager-resolution.entity.ts +44 -0
- package/src/lib/organization/membership.entity.ts +50 -0
- package/src/lib/organization/org-unit-tree-commit-result.object.ts +8 -0
- package/src/lib/organization/org-unit.entity.ts +53 -0
- package/src/lib/organization/organization-summary.object.ts +16 -0
- package/src/lib/organization/organization.enums.ts +19 -0
- package/src/lib/organization/organization.module.ts +27 -0
- package/src/lib/organization/organization.mutations.ts +115 -0
- package/src/lib/organization/organization.queries.ts +191 -0
- package/src/lib/organization/organization.service.spec.ts +835 -0
- package/src/lib/organization/organization.service.ts +1245 -0
- package/src/lib/organization/position.entity.ts +39 -0
- package/src/lib/organization/resolved-manager.object.ts +10 -0
- package/src/lib/signature/signature-options.spec.ts +60 -0
- package/src/lib/signature/signature-options.ts +120 -0
- package/src/lib/signature/signature-verification.object.ts +16 -0
- package/src/lib/signature/signature.entity.ts +62 -0
- package/src/lib/signature/signature.module.ts +80 -0
- package/src/lib/signature/signature.queries.ts +37 -0
- package/src/lib/signature/signature.service.spec.ts +134 -0
- package/src/lib/signature/signature.service.ts +205 -0
- package/src/lib/template/approval-template-category.entity.ts +40 -0
- package/src/lib/template/approval-template-version.entity.ts +82 -0
- package/src/lib/template/approval-template.entity.ts +64 -0
- package/src/lib/template/compose-approval-template.object.ts +23 -0
- package/src/lib/template/compose-template.mutations.ts +22 -0
- package/src/lib/template/dto/approval-template.input.ts +147 -0
- package/src/lib/template/dto/compose-approval-template.input.ts +80 -0
- package/src/lib/template/template.enums.ts +30 -0
- package/src/lib/template/template.module.ts +33 -0
- package/src/lib/template/template.mutations.ts +106 -0
- package/src/lib/template/template.queries.ts +119 -0
- package/src/lib/template/template.service.spec.ts +822 -0
- package/src/lib/template/template.service.ts +1082 -0
- package/src/lib/template/workflow-definition.validator.spec.ts +595 -0
- package/src/lib/template/workflow-definition.validator.ts +539 -0
- package/src/lib/testing/cel-js.jest.ts +46 -0
- package/src/lib/workflow-engine/activity-log.entity.ts +48 -0
- package/src/lib/workflow-engine/adhoc-directive.entity.ts +90 -0
- package/src/lib/workflow-engine/adhoc.enums.ts +42 -0
- package/src/lib/workflow-engine/approval-instance-page-info.object.ts +22 -0
- package/src/lib/workflow-engine/approval-instance.entity.ts +86 -0
- package/src/lib/workflow-engine/dto/adhoc-notification.input.ts +18 -0
- package/src/lib/workflow-engine/dto/adhoc-target.input.ts +52 -0
- package/src/lib/workflow-engine/dto/cancel-approval-instance.input.ts +18 -0
- package/src/lib/workflow-engine/dto/decide-task.input.ts +33 -0
- package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.ts +22 -0
- package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.ts +22 -0
- package/src/lib/workflow-engine/dto/submit-approval-instance.input.ts +27 -0
- package/src/lib/workflow-engine/task-candidate.entity.ts +56 -0
- package/src/lib/workflow-engine/task-decision.entity.ts +43 -0
- package/src/lib/workflow-engine/task.entity.ts +102 -0
- package/src/lib/workflow-engine/workflow-condition-evaluator.ts +168 -0
- package/src/lib/workflow-engine/workflow-dashboard-summary.object.ts +22 -0
- package/src/lib/workflow-engine/workflow-dry-run.object.ts +58 -0
- package/src/lib/workflow-engine/workflow-engine.enums.ts +102 -0
- package/src/lib/workflow-engine/workflow-engine.module.ts +77 -0
- package/src/lib/workflow-engine/workflow-engine.mutations.ts +193 -0
- package/src/lib/workflow-engine/workflow-engine.queries.ts +241 -0
- package/src/lib/workflow-engine/workflow-engine.service.spec.ts +3345 -0
- package/src/lib/workflow-engine/workflow-engine.service.ts +6022 -0
- package/src/lib/workflow-engine/{workflow-engine.tokens.d.ts → workflow-engine.tokens.ts} +9 -3
- package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.ts +69 -0
- package/src/lib/workflow-engine/workflow-token.entity.ts +40 -0
- package/tsconfig.json +24 -0
- package/tsconfig.lib.json +16 -0
- package/tsconfig.spec.json +16 -0
- package/src/index.js +0 -18
- package/src/index.js.map +0 -1
- package/src/lib/attachment/attachment-options.d.ts +0 -44
- package/src/lib/attachment/attachment-options.js +0 -62
- package/src/lib/attachment/attachment-options.js.map +0 -1
- package/src/lib/attachment/attachment-storage.provider.d.ts +0 -4
- package/src/lib/attachment/attachment-storage.provider.js +0 -35
- package/src/lib/attachment/attachment-storage.provider.js.map +0 -1
- package/src/lib/attachment/attachment-storage.token.js +0 -5
- package/src/lib/attachment/attachment-storage.token.js.map +0 -1
- package/src/lib/attachment/attachment.controller.d.ts +0 -8
- package/src/lib/attachment/attachment.controller.js +0 -38
- package/src/lib/attachment/attachment.controller.js.map +0 -1
- package/src/lib/attachment/attachment.entity.d.ts +0 -14
- package/src/lib/attachment/attachment.entity.js +0 -74
- package/src/lib/attachment/attachment.entity.js.map +0 -1
- package/src/lib/attachment/attachment.module.d.ts +0 -27
- package/src/lib/attachment/attachment.module.js +0 -103
- package/src/lib/attachment/attachment.module.js.map +0 -1
- package/src/lib/attachment/attachment.mutations.d.ts +0 -8
- package/src/lib/attachment/attachment.mutations.js +0 -35
- package/src/lib/attachment/attachment.mutations.js.map +0 -1
- package/src/lib/attachment/attachment.queries.d.ts +0 -9
- package/src/lib/attachment/attachment.queries.js +0 -78
- package/src/lib/attachment/attachment.queries.js.map +0 -1
- package/src/lib/attachment/attachment.service.d.ts +0 -49
- package/src/lib/attachment/attachment.service.js +0 -276
- package/src/lib/attachment/attachment.service.js.map +0 -1
- package/src/lib/attachment/dto/upload-attachment.input.d.ts +0 -11
- package/src/lib/attachment/dto/upload-attachment.input.js +0 -68
- package/src/lib/attachment/dto/upload-attachment.input.js.map +0 -1
- package/src/lib/attachment/index.js +0 -9
- package/src/lib/attachment/index.js.map +0 -1
- package/src/lib/bpm/bpm-root.module.d.ts +0 -155
- package/src/lib/bpm/bpm-root.module.js +0 -170
- package/src/lib/bpm/bpm-root.module.js.map +0 -1
- package/src/lib/bpm/index.js +0 -5
- package/src/lib/bpm/index.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth-context.d.ts +0 -24
- package/src/lib/bpm-auth/bpm-auth-context.extractor.d.ts +0 -4
- package/src/lib/bpm-auth/bpm-auth-context.extractor.js +0 -69
- package/src/lib/bpm-auth/bpm-auth-context.extractor.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth-context.js +0 -15
- package/src/lib/bpm-auth/bpm-auth-context.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth.authorization.d.ts +0 -12
- package/src/lib/bpm-auth/bpm-auth.authorization.js +0 -67
- package/src/lib/bpm-auth/bpm-auth.authorization.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth.decorators.d.ts +0 -3
- package/src/lib/bpm-auth/bpm-auth.decorators.js +0 -11
- package/src/lib/bpm-auth/bpm-auth.decorators.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth.guard.d.ts +0 -7
- package/src/lib/bpm-auth/bpm-auth.guard.js +0 -24
- package/src/lib/bpm-auth/bpm-auth.guard.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth.module.d.ts +0 -6
- package/src/lib/bpm-auth/bpm-auth.module.js +0 -69
- package/src/lib/bpm-auth/bpm-auth.module.js.map +0 -1
- package/src/lib/bpm-auth/bpm-auth.options.d.ts +0 -11
- package/src/lib/bpm-auth/bpm-auth.options.js +0 -3
- package/src/lib/bpm-auth/bpm-auth.options.js.map +0 -1
- package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.d.ts +0 -10
- package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.js +0 -40
- package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.js.map +0 -1
- package/src/lib/bpm-auth/index.js +0 -10
- package/src/lib/bpm-auth/index.js.map +0 -1
- package/src/lib/common/filters/all-exceptions.filter.d.ts +0 -25
- package/src/lib/common/filters/all-exceptions.filter.js +0 -93
- package/src/lib/common/filters/all-exceptions.filter.js.map +0 -1
- package/src/lib/common/index.js +0 -5
- package/src/lib/common/index.js.map +0 -1
- package/src/lib/common/iso-duration.d.ts +0 -1
- package/src/lib/common/iso-duration.js +0 -27
- package/src/lib/common/iso-duration.js.map +0 -1
- package/src/lib/condition/condition.module.d.ts +0 -2
- package/src/lib/condition/condition.module.js +0 -16
- package/src/lib/condition/condition.module.js.map +0 -1
- package/src/lib/condition/condition.service.d.ts +0 -16
- package/src/lib/condition/condition.service.js +0 -82
- package/src/lib/condition/condition.service.js.map +0 -1
- package/src/lib/condition/index.js +0 -6
- package/src/lib/condition/index.js.map +0 -1
- package/src/lib/database/data-source.d.ts +0 -4
- package/src/lib/database/data-source.js +0 -7
- package/src/lib/database/data-source.js.map +0 -1
- package/src/lib/database/index.js +0 -6
- package/src/lib/database/index.js.map +0 -1
- package/src/lib/database/migration-runner.d.ts +0 -1
- package/src/lib/database/migration-runner.js +0 -25
- package/src/lib/database/migration-runner.js.map +0 -1
- package/src/lib/database/reconcile-legacy-migrations.d.ts +0 -13
- package/src/lib/database/reconcile-legacy-migrations.js +0 -70
- package/src/lib/database/reconcile-legacy-migrations.js.map +0 -1
- package/src/lib/database/typeorm.config.d.ts +0 -14
- package/src/lib/database/typeorm.config.js +0 -135
- package/src/lib/database/typeorm.config.js.map +0 -1
- package/src/lib/delegation/delegation-rule.entity.d.ts +0 -19
- package/src/lib/delegation/delegation-rule.entity.js +0 -99
- package/src/lib/delegation/delegation-rule.entity.js.map +0 -1
- package/src/lib/delegation/delegation.enums.d.ts +0 -10
- package/src/lib/delegation/delegation.enums.js +0 -23
- package/src/lib/delegation/delegation.enums.js.map +0 -1
- package/src/lib/delegation/delegation.module.d.ts +0 -2
- package/src/lib/delegation/delegation.module.js +0 -22
- package/src/lib/delegation/delegation.module.js.map +0 -1
- package/src/lib/delegation/delegation.mutations.d.ts +0 -11
- package/src/lib/delegation/delegation.mutations.js +0 -87
- package/src/lib/delegation/delegation.mutations.js.map +0 -1
- package/src/lib/delegation/delegation.queries.d.ts +0 -10
- package/src/lib/delegation/delegation.queries.js +0 -91
- package/src/lib/delegation/delegation.queries.js.map +0 -1
- package/src/lib/delegation/delegation.service.d.ts +0 -56
- package/src/lib/delegation/delegation.service.js +0 -268
- package/src/lib/delegation/delegation.service.js.map +0 -1
- package/src/lib/delegation/dto/delegation-rule.input.d.ts +0 -24
- package/src/lib/delegation/dto/delegation-rule.input.js +0 -143
- package/src/lib/delegation/dto/delegation-rule.input.js.map +0 -1
- package/src/lib/delegation/index.js +0 -9
- package/src/lib/delegation/index.js.map +0 -1
- package/src/lib/form/dto/form-definition.input.d.ts +0 -26
- package/src/lib/form/dto/form-definition.input.js +0 -126
- package/src/lib/form/dto/form-definition.input.js.map +0 -1
- package/src/lib/form/form-definition-version.entity.d.ts +0 -17
- package/src/lib/form/form-definition-version.entity.js +0 -84
- package/src/lib/form/form-definition-version.entity.js.map +0 -1
- package/src/lib/form/form-definition.entity.d.ts +0 -13
- package/src/lib/form/form-definition.entity.js +0 -66
- package/src/lib/form/form-definition.entity.js.map +0 -1
- package/src/lib/form/form-schema-lint.object.d.ts +0 -4
- package/src/lib/form/form-schema-lint.object.js +0 -20
- package/src/lib/form/form-schema-lint.object.js.map +0 -1
- package/src/lib/form/form-schema.validator.d.ts +0 -13
- package/src/lib/form/form-schema.validator.js +0 -354
- package/src/lib/form/form-schema.validator.js.map +0 -1
- package/src/lib/form/form.enums.d.ts +0 -9
- package/src/lib/form/form.enums.js +0 -22
- package/src/lib/form/form.enums.js.map +0 -1
- package/src/lib/form/form.module.d.ts +0 -2
- package/src/lib/form/form.module.js +0 -27
- package/src/lib/form/form.module.js.map +0 -1
- package/src/lib/form/form.mutations.d.ts +0 -14
- package/src/lib/form/form.mutations.js +0 -89
- package/src/lib/form/form.mutations.js.map +0 -1
- package/src/lib/form/form.queries.d.ts +0 -16
- package/src/lib/form/form.queries.js +0 -96
- package/src/lib/form/form.queries.js.map +0 -1
- package/src/lib/form/form.service.d.ts +0 -49
- package/src/lib/form/form.service.js +0 -346
- package/src/lib/form/form.service.js.map +0 -1
- package/src/lib/form/index.js +0 -12
- package/src/lib/form/index.js.map +0 -1
- package/src/lib/identity/identity-options.d.ts +0 -13
- package/src/lib/identity/identity-options.js +0 -20
- package/src/lib/identity/identity-options.js.map +0 -1
- package/src/lib/identity/identity.module.d.ts +0 -17
- package/src/lib/identity/identity.module.js +0 -65
- package/src/lib/identity/identity.module.js.map +0 -1
- package/src/lib/identity/identity.queries.d.ts +0 -12
- package/src/lib/identity/identity.queries.js +0 -79
- package/src/lib/identity/identity.queries.js.map +0 -1
- package/src/lib/identity/identity.service.d.ts +0 -22
- package/src/lib/identity/identity.service.js +0 -141
- package/src/lib/identity/identity.service.js.map +0 -1
- package/src/lib/identity/index.js +0 -8
- package/src/lib/identity/index.js.map +0 -1
- package/src/lib/identity/member-base.adapter.d.ts +0 -95
- package/src/lib/identity/member-base.adapter.js +0 -137
- package/src/lib/identity/member-base.adapter.js.map +0 -1
- package/src/lib/identity/member-metadata-cache.entity.d.ts +0 -8
- package/src/lib/identity/member-metadata-cache.entity.js +0 -39
- package/src/lib/identity/member-metadata-cache.entity.js.map +0 -1
- package/src/lib/identity/member-not-found.exception.js +0 -26
- package/src/lib/identity/member-not-found.exception.js.map +0 -1
- package/src/lib/identity/member-profile.object.d.ts +0 -8
- package/src/lib/identity/member-profile.object.js +0 -37
- package/src/lib/identity/member-profile.object.js.map +0 -1
- package/src/lib/identity/member-resolver.interface.d.ts +0 -79
- package/src/lib/identity/member-resolver.interface.js +0 -19
- package/src/lib/identity/member-resolver.interface.js.map +0 -1
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.d.ts +0 -6
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.js +0 -17
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.js.map +0 -1
- package/src/lib/migrations/0000000001000-identity-organization-foundation.d.ts +0 -6
- package/src/lib/migrations/0000000001000-identity-organization-foundation.js.map +0 -1
- package/src/lib/migrations/0000000002000-form-builder-foundation.d.ts +0 -6
- package/src/lib/migrations/0000000002000-form-builder-foundation.js.map +0 -1
- package/src/lib/migrations/0000000003000-approval-template-foundation.d.ts +0 -6
- package/src/lib/migrations/0000000003000-approval-template-foundation.js.map +0 -1
- package/src/lib/migrations/0000000004000-workflow-engine-foundation.d.ts +0 -6
- package/src/lib/migrations/0000000004000-workflow-engine-foundation.js.map +0 -1
- package/src/lib/migrations/0000000005000-delegation-rules.d.ts +0 -6
- package/src/lib/migrations/0000000005000-delegation-rules.js.map +0 -1
- package/src/lib/migrations/0000000006000-notifications-sla.d.ts +0 -6
- package/src/lib/migrations/0000000006000-notifications-sla.js.map +0 -1
- package/src/lib/migrations/0000000007000-signatures-attachments.d.ts +0 -6
- package/src/lib/migrations/0000000007000-signatures-attachments.js.map +0 -1
- package/src/lib/migrations/0000000008000-approval-template-categories.d.ts +0 -6
- package/src/lib/migrations/0000000008000-approval-template-categories.js.map +0 -1
- package/src/lib/migrations/0000000009000-task-candidates.d.ts +0 -6
- package/src/lib/migrations/0000000009000-task-candidates.js.map +0 -1
- package/src/lib/migrations/0000000010000-notification-delivery-state.d.ts +0 -6
- package/src/lib/migrations/0000000010000-notification-delivery-state.js.map +0 -1
- package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.d.ts +0 -6
- package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.js +0 -22
- package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.js.map +0 -1
- package/src/lib/migrations/0000000012000-notification-sla-idempotency.d.ts +0 -6
- package/src/lib/migrations/0000000012000-notification-sla-idempotency.js +0 -21
- package/src/lib/migrations/0000000012000-notification-sla-idempotency.js.map +0 -1
- package/src/lib/migrations/0000000013000-workflow-query-indexes.d.ts +0 -6
- package/src/lib/migrations/0000000013000-workflow-query-indexes.js +0 -80
- package/src/lib/migrations/0000000013000-workflow-query-indexes.js.map +0 -1
- package/src/lib/migrations/0000000014000-notification-resolution.d.ts +0 -6
- package/src/lib/migrations/0000000014000-notification-resolution.js +0 -30
- package/src/lib/migrations/0000000014000-notification-resolution.js.map +0 -1
- package/src/lib/migrations/0000000015000-backfill-stale-notification-resolution.d.ts +0 -15
- package/src/lib/migrations/0000000015000-backfill-stale-notification-resolution.js.map +0 -1
- package/src/lib/migrations/0000000016000-archive-parallel-form-drafts.d.ts +0 -15
- package/src/lib/migrations/0000000016000-archive-parallel-form-drafts.js.map +0 -1
- package/src/lib/migrations/0000000017000-adhoc-directives.d.ts +0 -6
- package/src/lib/migrations/0000000017000-adhoc-directives.js.map +0 -1
- package/src/lib/migrations/index.d.ts +0 -20
- package/src/lib/migrations/index.js +0 -61
- package/src/lib/migrations/index.js.map +0 -1
- package/src/lib/notification/dto/notification-preference.input.d.ts +0 -9
- package/src/lib/notification/dto/notification-preference.input.js +0 -53
- package/src/lib/notification/dto/notification-preference.input.js.map +0 -1
- package/src/lib/notification/index.js +0 -11
- package/src/lib/notification/index.js.map +0 -1
- package/src/lib/notification/notification-delivery-scheduler.service.d.ts +0 -13
- package/src/lib/notification/notification-delivery-scheduler.service.js +0 -53
- package/src/lib/notification/notification-delivery-scheduler.service.js.map +0 -1
- package/src/lib/notification/notification-delivery.service.d.ts +0 -23
- package/src/lib/notification/notification-delivery.service.js +0 -245
- package/src/lib/notification/notification-delivery.service.js.map +0 -1
- package/src/lib/notification/notification-dispatcher.token.d.ts +0 -7
- package/src/lib/notification/notification-dispatcher.token.js +0 -5
- package/src/lib/notification/notification-dispatcher.token.js.map +0 -1
- package/src/lib/notification/notification-options.d.ts +0 -215
- package/src/lib/notification/notification-options.js +0 -128
- package/src/lib/notification/notification-options.js.map +0 -1
- package/src/lib/notification/notification-options.module.d.ts +0 -23
- package/src/lib/notification/notification-options.module.js +0 -41
- package/src/lib/notification/notification-options.module.js.map +0 -1
- package/src/lib/notification/notification-preference.entity.d.ts +0 -10
- package/src/lib/notification/notification-preference.entity.js +0 -50
- package/src/lib/notification/notification-preference.entity.js.map +0 -1
- package/src/lib/notification/notification-sla-scheduler.service.d.ts +0 -13
- package/src/lib/notification/notification-sla-scheduler.service.js +0 -51
- package/src/lib/notification/notification-sla-scheduler.service.js.map +0 -1
- package/src/lib/notification/notification-template.d.ts +0 -13
- package/src/lib/notification/notification-template.js +0 -61
- package/src/lib/notification/notification-template.js.map +0 -1
- package/src/lib/notification/notification.entity.d.ts +0 -31
- package/src/lib/notification/notification.entity.js +0 -149
- package/src/lib/notification/notification.entity.js.map +0 -1
- package/src/lib/notification/notification.enums.d.ts +0 -38
- package/src/lib/notification/notification.enums.js +0 -63
- package/src/lib/notification/notification.enums.js.map +0 -1
- package/src/lib/notification/notification.module.d.ts +0 -2
- package/src/lib/notification/notification.module.js +0 -45
- package/src/lib/notification/notification.module.js.map +0 -1
- package/src/lib/notification/notification.mutations.d.ts +0 -11
- package/src/lib/notification/notification.mutations.js +0 -64
- package/src/lib/notification/notification.mutations.js.map +0 -1
- package/src/lib/notification/notification.queries.d.ts +0 -11
- package/src/lib/notification/notification.queries.js +0 -77
- package/src/lib/notification/notification.queries.js.map +0 -1
- package/src/lib/notification/notification.service.d.ts +0 -121
- package/src/lib/notification/notification.service.js +0 -713
- package/src/lib/notification/notification.service.js.map +0 -1
- package/src/lib/organization/dto/manager-resolution.input.d.ts +0 -18
- package/src/lib/organization/dto/manager-resolution.input.js +0 -107
- package/src/lib/organization/dto/manager-resolution.input.js.map +0 -1
- package/src/lib/organization/dto/membership.input.d.ts +0 -16
- package/src/lib/organization/dto/membership.input.js +0 -99
- package/src/lib/organization/dto/membership.input.js.map +0 -1
- package/src/lib/organization/dto/org-unit.input.d.ts +0 -24
- package/src/lib/organization/dto/org-unit.input.js +0 -119
- package/src/lib/organization/dto/org-unit.input.js.map +0 -1
- package/src/lib/organization/dto/position.input.d.ts +0 -13
- package/src/lib/organization/dto/position.input.js +0 -70
- package/src/lib/organization/dto/position.input.js.map +0 -1
- package/src/lib/organization/index.js +0 -16
- package/src/lib/organization/index.js.map +0 -1
- package/src/lib/organization/json-metadata.d.ts +0 -1
- package/src/lib/organization/json-metadata.js +0 -14
- package/src/lib/organization/json-metadata.js.map +0 -1
- package/src/lib/organization/manager-resolution.entity.d.ts +0 -11
- package/src/lib/organization/manager-resolution.entity.js +0 -55
- package/src/lib/organization/manager-resolution.entity.js.map +0 -1
- package/src/lib/organization/membership.entity.d.ts +0 -11
- package/src/lib/organization/membership.entity.js +0 -60
- package/src/lib/organization/membership.entity.js.map +0 -1
- package/src/lib/organization/org-unit-tree-commit-result.object.d.ts +0 -4
- package/src/lib/organization/org-unit-tree-commit-result.object.js +0 -17
- package/src/lib/organization/org-unit-tree-commit-result.object.js.map +0 -1
- package/src/lib/organization/org-unit.entity.d.ts +0 -13
- package/src/lib/organization/org-unit.entity.js +0 -64
- package/src/lib/organization/org-unit.entity.js.map +0 -1
- package/src/lib/organization/organization-summary.object.d.ts +0 -6
- package/src/lib/organization/organization-summary.object.js +0 -28
- package/src/lib/organization/organization-summary.object.js.map +0 -1
- package/src/lib/organization/organization.enums.d.ts +0 -11
- package/src/lib/organization/organization.enums.js +0 -22
- package/src/lib/organization/organization.enums.js.map +0 -1
- package/src/lib/organization/organization.module.d.ts +0 -2
- package/src/lib/organization/organization.module.js +0 -35
- package/src/lib/organization/organization.module.js.map +0 -1
- package/src/lib/organization/organization.mutations.d.ts +0 -26
- package/src/lib/organization/organization.mutations.js +0 -148
- package/src/lib/organization/organization.mutations.js.map +0 -1
- package/src/lib/organization/organization.queries.d.ts +0 -23
- package/src/lib/organization/organization.queries.js +0 -202
- package/src/lib/organization/organization.queries.js.map +0 -1
- package/src/lib/organization/organization.service.d.ts +0 -102
- package/src/lib/organization/organization.service.js +0 -751
- package/src/lib/organization/organization.service.js.map +0 -1
- package/src/lib/organization/position.entity.d.ts +0 -9
- package/src/lib/organization/position.entity.js +0 -48
- package/src/lib/organization/position.entity.js.map +0 -1
- package/src/lib/organization/resolved-manager.object.d.ts +0 -4
- package/src/lib/organization/resolved-manager.object.js +0 -20
- package/src/lib/organization/resolved-manager.object.js.map +0 -1
- package/src/lib/signature/index.js +0 -8
- package/src/lib/signature/index.js.map +0 -1
- package/src/lib/signature/signature-options.d.ts +0 -33
- package/src/lib/signature/signature-options.js +0 -51
- package/src/lib/signature/signature-options.js.map +0 -1
- package/src/lib/signature/signature-verification.object.d.ts +0 -6
- package/src/lib/signature/signature-verification.object.js +0 -28
- package/src/lib/signature/signature-verification.object.js.map +0 -1
- package/src/lib/signature/signature.entity.d.ts +0 -16
- package/src/lib/signature/signature.entity.js +0 -88
- package/src/lib/signature/signature.entity.js.map +0 -1
- package/src/lib/signature/signature.module.d.ts +0 -11
- package/src/lib/signature/signature.module.js +0 -60
- package/src/lib/signature/signature.module.js.map +0 -1
- package/src/lib/signature/signature.queries.d.ts +0 -11
- package/src/lib/signature/signature.queries.js +0 -46
- package/src/lib/signature/signature.queries.js.map +0 -1
- package/src/lib/signature/signature.service.d.ts +0 -25
- package/src/lib/signature/signature.service.js +0 -124
- package/src/lib/signature/signature.service.js.map +0 -1
- package/src/lib/template/approval-template-category.entity.d.ts +0 -9
- package/src/lib/template/approval-template-category.entity.js +0 -49
- package/src/lib/template/approval-template-category.entity.js.map +0 -1
- package/src/lib/template/approval-template-version.entity.d.ts +0 -21
- package/src/lib/template/approval-template-version.entity.js +0 -106
- package/src/lib/template/approval-template-version.entity.js.map +0 -1
- package/src/lib/template/approval-template.entity.d.ts +0 -14
- package/src/lib/template/approval-template.entity.js +0 -74
- package/src/lib/template/approval-template.entity.js.map +0 -1
- package/src/lib/template/compose-approval-template.object.d.ts +0 -11
- package/src/lib/template/compose-approval-template.object.js +0 -36
- package/src/lib/template/compose-approval-template.object.js.map +0 -1
- package/src/lib/template/compose-template.mutations.d.ts +0 -8
- package/src/lib/template/compose-template.mutations.js +0 -32
- package/src/lib/template/compose-template.mutations.js.map +0 -1
- package/src/lib/template/dto/approval-template.input.d.ts +0 -36
- package/src/lib/template/dto/approval-template.input.js +0 -187
- package/src/lib/template/dto/approval-template.input.js.map +0 -1
- package/src/lib/template/dto/compose-approval-template.input.d.ts +0 -17
- package/src/lib/template/dto/compose-approval-template.input.js +0 -99
- package/src/lib/template/dto/compose-approval-template.input.js.map +0 -1
- package/src/lib/template/index.js +0 -14
- package/src/lib/template/index.js.map +0 -1
- package/src/lib/template/template.enums.d.ts +0 -14
- package/src/lib/template/template.enums.js +0 -31
- package/src/lib/template/template.enums.js.map +0 -1
- package/src/lib/template/template.module.d.ts +0 -2
- package/src/lib/template/template.module.js +0 -41
- package/src/lib/template/template.module.js.map +0 -1
- package/src/lib/template/template.mutations.d.ts +0 -20
- package/src/lib/template/template.mutations.js +0 -139
- package/src/lib/template/template.mutations.js.map +0 -1
- package/src/lib/template/template.queries.d.ts +0 -16
- package/src/lib/template/template.queries.js +0 -133
- package/src/lib/template/template.queries.js.map +0 -1
- package/src/lib/template/template.service.d.ts +0 -83
- package/src/lib/template/template.service.js +0 -654
- package/src/lib/template/template.service.js.map +0 -1
- package/src/lib/template/workflow-definition.validator.d.ts +0 -9
- package/src/lib/template/workflow-definition.validator.js +0 -362
- package/src/lib/template/workflow-definition.validator.js.map +0 -1
- package/src/lib/testing/cel-js.jest.d.ts +0 -15
- package/src/lib/testing/cel-js.jest.js +0 -27
- package/src/lib/testing/cel-js.jest.js.map +0 -1
- package/src/lib/workflow-engine/activity-log.entity.d.ts +0 -12
- package/src/lib/workflow-engine/activity-log.entity.js +0 -62
- package/src/lib/workflow-engine/activity-log.entity.js.map +0 -1
- package/src/lib/workflow-engine/adhoc-directive.entity.d.ts +0 -31
- package/src/lib/workflow-engine/adhoc-directive.entity.js +0 -105
- package/src/lib/workflow-engine/adhoc-directive.entity.js.map +0 -1
- package/src/lib/workflow-engine/adhoc.enums.d.ts +0 -21
- package/src/lib/workflow-engine/adhoc.enums.js +0 -42
- package/src/lib/workflow-engine/adhoc.enums.js.map +0 -1
- package/src/lib/workflow-engine/approval-instance-page-info.object.d.ts +0 -8
- package/src/lib/workflow-engine/approval-instance-page-info.object.js +0 -36
- package/src/lib/workflow-engine/approval-instance-page-info.object.js.map +0 -1
- package/src/lib/workflow-engine/approval-instance.entity.d.ts +0 -22
- package/src/lib/workflow-engine/approval-instance.entity.js +0 -113
- package/src/lib/workflow-engine/approval-instance.entity.js.map +0 -1
- package/src/lib/workflow-engine/dto/adhoc-notification.input.d.ts +0 -6
- package/src/lib/workflow-engine/dto/adhoc-notification.input.js +0 -28
- package/src/lib/workflow-engine/dto/adhoc-notification.input.js.map +0 -1
- package/src/lib/workflow-engine/dto/adhoc-target.input.d.ts +0 -16
- package/src/lib/workflow-engine/dto/adhoc-target.input.js +0 -61
- package/src/lib/workflow-engine/dto/adhoc-target.input.js.map +0 -1
- package/src/lib/workflow-engine/dto/cancel-approval-instance.input.d.ts +0 -5
- package/src/lib/workflow-engine/dto/cancel-approval-instance.input.js +0 -29
- package/src/lib/workflow-engine/dto/cancel-approval-instance.input.js.map +0 -1
- package/src/lib/workflow-engine/dto/decide-task.input.d.ts +0 -9
- package/src/lib/workflow-engine/dto/decide-task.input.js +0 -47
- package/src/lib/workflow-engine/dto/decide-task.input.js.map +0 -1
- package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.d.ts +0 -6
- package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.js +0 -34
- package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.js.map +0 -1
- package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.d.ts +0 -6
- package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.js +0 -34
- package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.js.map +0 -1
- package/src/lib/workflow-engine/dto/submit-approval-instance.input.d.ts +0 -7
- package/src/lib/workflow-engine/dto/submit-approval-instance.input.js +0 -40
- package/src/lib/workflow-engine/dto/submit-approval-instance.input.js.map +0 -1
- package/src/lib/workflow-engine/index.js +0 -28
- package/src/lib/workflow-engine/index.js.map +0 -1
- package/src/lib/workflow-engine/task-candidate.entity.d.ts +0 -14
- package/src/lib/workflow-engine/task-candidate.entity.js +0 -72
- package/src/lib/workflow-engine/task-candidate.entity.js.map +0 -1
- package/src/lib/workflow-engine/task-decision.entity.d.ts +0 -12
- package/src/lib/workflow-engine/task-decision.entity.js +0 -60
- package/src/lib/workflow-engine/task-decision.entity.js.map +0 -1
- package/src/lib/workflow-engine/task.entity.d.ts +0 -25
- package/src/lib/workflow-engine/task.entity.js +0 -130
- package/src/lib/workflow-engine/task.entity.js.map +0 -1
- package/src/lib/workflow-engine/workflow-condition-evaluator.d.ts +0 -5
- package/src/lib/workflow-engine/workflow-condition-evaluator.js +0 -107
- package/src/lib/workflow-engine/workflow-condition-evaluator.js.map +0 -1
- package/src/lib/workflow-engine/workflow-dashboard-summary.object.d.ts +0 -8
- package/src/lib/workflow-engine/workflow-dashboard-summary.object.js +0 -36
- package/src/lib/workflow-engine/workflow-dashboard-summary.object.js.map +0 -1
- package/src/lib/workflow-engine/workflow-dry-run.object.d.ts +0 -21
- package/src/lib/workflow-engine/workflow-dry-run.object.js +0 -86
- package/src/lib/workflow-engine/workflow-dry-run.object.js.map +0 -1
- package/src/lib/workflow-engine/workflow-engine.enums.d.ts +0 -61
- package/src/lib/workflow-engine/workflow-engine.enums.js +0 -98
- package/src/lib/workflow-engine/workflow-engine.enums.js.map +0 -1
- package/src/lib/workflow-engine/workflow-engine.module.d.ts +0 -9
- package/src/lib/workflow-engine/workflow-engine.module.js +0 -78
- package/src/lib/workflow-engine/workflow-engine.module.js.map +0 -1
- package/src/lib/workflow-engine/workflow-engine.mutations.d.ts +0 -29
- package/src/lib/workflow-engine/workflow-engine.mutations.js +0 -218
- package/src/lib/workflow-engine/workflow-engine.mutations.js.map +0 -1
- package/src/lib/workflow-engine/workflow-engine.queries.d.ts +0 -31
- package/src/lib/workflow-engine/workflow-engine.queries.js +0 -237
- package/src/lib/workflow-engine/workflow-engine.queries.js.map +0 -1
- package/src/lib/workflow-engine/workflow-engine.service.d.ts +0 -188
- package/src/lib/workflow-engine/workflow-engine.service.js +0 -3561
- package/src/lib/workflow-engine/workflow-engine.service.js.map +0 -1
- package/src/lib/workflow-engine/workflow-engine.tokens.js +0 -5
- package/src/lib/workflow-engine/workflow-engine.tokens.js.map +0 -1
- package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.d.ts +0 -18
- package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.js +0 -39
- package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.js.map +0 -1
- package/src/lib/workflow-engine/workflow-token.entity.d.ts +0 -10
- package/src/lib/workflow-engine/workflow-token.entity.js +0 -50
- package/src/lib/workflow-engine/workflow-token.entity.js.map +0 -1
- /package/src/{index.d.ts → index.ts} +0 -0
- /package/src/lib/attachment/{index.d.ts → index.ts} +0 -0
- /package/src/lib/bpm/{index.d.ts → index.ts} +0 -0
- /package/src/lib/bpm-auth/{index.d.ts → index.ts} +0 -0
- /package/src/lib/common/{index.d.ts → index.ts} +0 -0
- /package/src/lib/condition/{index.d.ts → index.ts} +0 -0
- /package/src/lib/database/{index.d.ts → index.ts} +0 -0
- /package/src/lib/delegation/{index.d.ts → index.ts} +0 -0
- /package/src/lib/form/{index.d.ts → index.ts} +0 -0
- /package/src/lib/identity/{index.d.ts → index.ts} +0 -0
- /package/src/lib/notification/{index.d.ts → index.ts} +0 -0
- /package/src/lib/organization/{index.d.ts → index.ts} +0 -0
- /package/src/lib/signature/{index.d.ts → index.ts} +0 -0
- /package/src/lib/template/{index.d.ts → index.ts} +0 -0
- /package/src/lib/workflow-engine/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,1129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ServiceTaskNode,
|
|
3
|
+
UserTaskNode,
|
|
4
|
+
} from '@rytass/bpm-core-shared/workflow';
|
|
5
|
+
import {
|
|
6
|
+
Inject,
|
|
7
|
+
Injectable,
|
|
8
|
+
Logger,
|
|
9
|
+
NotFoundException,
|
|
10
|
+
Optional,
|
|
11
|
+
} from '@nestjs/common';
|
|
12
|
+
import { ModuleRef } from '@nestjs/core';
|
|
13
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
14
|
+
import {
|
|
15
|
+
EntityManager,
|
|
16
|
+
In,
|
|
17
|
+
IsNull,
|
|
18
|
+
LessThanOrEqual,
|
|
19
|
+
MoreThan,
|
|
20
|
+
Not,
|
|
21
|
+
Repository,
|
|
22
|
+
} from 'typeorm';
|
|
23
|
+
import { parseIsoDurationToMilliseconds } from '../common/iso-duration';
|
|
24
|
+
import { ActivityLogEntity } from '../workflow-engine/activity-log.entity';
|
|
25
|
+
import { ApprovalInstanceEntity } from '../workflow-engine/approval-instance.entity';
|
|
26
|
+
import { OrganizationService } from '../organization/organization.service';
|
|
27
|
+
import { TaskCandidateEntity } from '../workflow-engine/task-candidate.entity';
|
|
28
|
+
import { TaskEntity } from '../workflow-engine/task.entity';
|
|
29
|
+
import {
|
|
30
|
+
BPM_WORKFLOW_ENGINE_SERVICE,
|
|
31
|
+
BPMWorkflowEngineService,
|
|
32
|
+
} from '../workflow-engine/workflow-engine.tokens';
|
|
33
|
+
import {
|
|
34
|
+
ActivityLogEventTypeEnum,
|
|
35
|
+
TaskDecisionActionEnum,
|
|
36
|
+
TaskCandidateStatusEnum,
|
|
37
|
+
TaskStatusEnum,
|
|
38
|
+
} from '../workflow-engine/workflow-engine.enums';
|
|
39
|
+
import { NotificationDeliveryService } from './notification-delivery.service';
|
|
40
|
+
import { NotificationPreferenceEntity } from './notification-preference.entity';
|
|
41
|
+
import { NotificationEntity } from './notification.entity';
|
|
42
|
+
import {
|
|
43
|
+
NotificationChannelEnum,
|
|
44
|
+
NotificationResolutionEnum,
|
|
45
|
+
NotificationStatusEnum,
|
|
46
|
+
NotificationTypeEnum,
|
|
47
|
+
} from './notification.enums';
|
|
48
|
+
|
|
49
|
+
const ACTIONABLE_NOTIFICATION_TYPES: readonly NotificationTypeEnum[] = [
|
|
50
|
+
NotificationTypeEnum.TASK_ASSIGNED,
|
|
51
|
+
NotificationTypeEnum.TASK_TRANSFERRED,
|
|
52
|
+
];
|
|
53
|
+
import {
|
|
54
|
+
BPM_NOTIFICATION_OPTIONS,
|
|
55
|
+
BPMResolvedNotificationOptions,
|
|
56
|
+
DEFAULT_BPM_NOTIFICATION_OPTIONS,
|
|
57
|
+
} from './notification-options';
|
|
58
|
+
import { renderNotificationTemplate } from './notification-template';
|
|
59
|
+
import { UpdateNotificationPreferenceInput } from './dto/notification-preference.input';
|
|
60
|
+
|
|
61
|
+
interface CreateNotificationInput {
|
|
62
|
+
readonly channels: readonly NotificationChannelEnum[];
|
|
63
|
+
readonly instanceId: string | null;
|
|
64
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
65
|
+
readonly recipientMemberId: string;
|
|
66
|
+
readonly taskId: string | null;
|
|
67
|
+
readonly type: NotificationTypeEnum;
|
|
68
|
+
readonly customTemplate?: string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface SlaScanResult {
|
|
72
|
+
readonly overdueCount: number;
|
|
73
|
+
readonly warningCount: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Injectable()
|
|
77
|
+
export class NotificationService {
|
|
78
|
+
private readonly logger = new Logger(NotificationService.name);
|
|
79
|
+
|
|
80
|
+
constructor(
|
|
81
|
+
@InjectRepository(NotificationEntity)
|
|
82
|
+
private readonly notificationRepository: Repository<NotificationEntity>,
|
|
83
|
+
@InjectRepository(NotificationPreferenceEntity)
|
|
84
|
+
private readonly notificationPreferenceRepository: Repository<NotificationPreferenceEntity>,
|
|
85
|
+
@InjectRepository(TaskEntity)
|
|
86
|
+
private readonly taskRepository: Repository<TaskEntity>,
|
|
87
|
+
@InjectRepository(TaskCandidateEntity)
|
|
88
|
+
private readonly taskCandidateRepository: Repository<TaskCandidateEntity>,
|
|
89
|
+
@InjectRepository(ApprovalInstanceEntity)
|
|
90
|
+
private readonly approvalInstanceRepository: Repository<ApprovalInstanceEntity>,
|
|
91
|
+
@InjectRepository(ActivityLogEntity)
|
|
92
|
+
private readonly activityLogRepository: Repository<ActivityLogEntity>,
|
|
93
|
+
private readonly deliveryService: NotificationDeliveryService,
|
|
94
|
+
private readonly moduleRef: ModuleRef,
|
|
95
|
+
@Optional()
|
|
96
|
+
@Inject(BPM_NOTIFICATION_OPTIONS)
|
|
97
|
+
private readonly notificationOptions: BPMResolvedNotificationOptions = DEFAULT_BPM_NOTIFICATION_OPTIONS,
|
|
98
|
+
) {}
|
|
99
|
+
|
|
100
|
+
async listNotifications({
|
|
101
|
+
includeRead = false,
|
|
102
|
+
page = 1,
|
|
103
|
+
pageSize = 10,
|
|
104
|
+
recipientMemberId,
|
|
105
|
+
}: {
|
|
106
|
+
readonly includeRead?: boolean;
|
|
107
|
+
readonly page?: number;
|
|
108
|
+
readonly pageSize?: number;
|
|
109
|
+
readonly recipientMemberId: string;
|
|
110
|
+
}): Promise<readonly NotificationEntity[]> {
|
|
111
|
+
const normalizedPageSize = normalizePageSize(pageSize);
|
|
112
|
+
|
|
113
|
+
return this.notificationRepository.find({
|
|
114
|
+
order: { createdAt: 'DESC' },
|
|
115
|
+
skip: (normalizePage(page) - 1) * normalizedPageSize,
|
|
116
|
+
take: normalizedPageSize,
|
|
117
|
+
where: {
|
|
118
|
+
channel: NotificationChannelEnum.IN_APP,
|
|
119
|
+
recipientMemberId,
|
|
120
|
+
...(includeRead ? {} : { status: Not(NotificationStatusEnum.READ) }),
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async countNotifications({
|
|
126
|
+
includeRead = false,
|
|
127
|
+
recipientMemberId,
|
|
128
|
+
}: {
|
|
129
|
+
readonly includeRead?: boolean;
|
|
130
|
+
readonly recipientMemberId: string;
|
|
131
|
+
}): Promise<number> {
|
|
132
|
+
return this.notificationRepository.count({
|
|
133
|
+
where: {
|
|
134
|
+
channel: NotificationChannelEnum.IN_APP,
|
|
135
|
+
recipientMemberId,
|
|
136
|
+
...(includeRead ? {} : { status: Not(NotificationStatusEnum.READ) }),
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async countUnreadNotifications(recipientMemberId: string): Promise<number> {
|
|
142
|
+
return this.notificationRepository.count({
|
|
143
|
+
where: {
|
|
144
|
+
channel: NotificationChannelEnum.IN_APP,
|
|
145
|
+
recipientMemberId,
|
|
146
|
+
status: Not(NotificationStatusEnum.READ),
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async markAllNotificationsRead({
|
|
152
|
+
recipientMemberId,
|
|
153
|
+
}: {
|
|
154
|
+
readonly recipientMemberId: string;
|
|
155
|
+
}): Promise<number> {
|
|
156
|
+
const trimmedRecipientMemberId = recipientMemberId.trim();
|
|
157
|
+
|
|
158
|
+
if (!trimmedRecipientMemberId) {
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const result = await this.notificationRepository.update(
|
|
163
|
+
{
|
|
164
|
+
channel: NotificationChannelEnum.IN_APP,
|
|
165
|
+
recipientMemberId: trimmedRecipientMemberId,
|
|
166
|
+
status: Not(NotificationStatusEnum.READ),
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
readAt: new Date(),
|
|
170
|
+
status: NotificationStatusEnum.READ,
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return result.affected ?? 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async markNotificationRead({
|
|
178
|
+
id,
|
|
179
|
+
readerMemberId,
|
|
180
|
+
}: {
|
|
181
|
+
readonly id: string;
|
|
182
|
+
readonly readerMemberId: string | null;
|
|
183
|
+
}): Promise<NotificationEntity> {
|
|
184
|
+
const notification = await this.notificationRepository.findOne({
|
|
185
|
+
where: { id },
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
if (!notification) {
|
|
189
|
+
throw new NotFoundException(`Notification ${id} was not found`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
readerMemberId &&
|
|
194
|
+
notification.recipientMemberId !== readerMemberId.trim()
|
|
195
|
+
) {
|
|
196
|
+
throw new NotFoundException(`Notification ${id} was not found`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return this.notificationRepository.save(
|
|
200
|
+
this.notificationRepository.create({
|
|
201
|
+
...notification,
|
|
202
|
+
readAt: notification.readAt ?? new Date(),
|
|
203
|
+
status: NotificationStatusEnum.READ,
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async getPreference(memberId: string): Promise<NotificationPreferenceEntity> {
|
|
209
|
+
const existingPreference =
|
|
210
|
+
await this.notificationPreferenceRepository.findOne({
|
|
211
|
+
where: { memberId },
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
existingPreference ??
|
|
216
|
+
createDefaultPreference(memberId, this.notificationOptions)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async updatePreference(
|
|
221
|
+
input: UpdateNotificationPreferenceInput,
|
|
222
|
+
): Promise<NotificationPreferenceEntity> {
|
|
223
|
+
const currentPreference = await this.getPreference(input.memberId);
|
|
224
|
+
|
|
225
|
+
return this.notificationPreferenceRepository.save({
|
|
226
|
+
...currentPreference,
|
|
227
|
+
emailDigestMode: input.emailDigestMode,
|
|
228
|
+
emailEnabled: input.emailEnabled,
|
|
229
|
+
inAppEnabled: input.inAppEnabled,
|
|
230
|
+
memberId: input.memberId,
|
|
231
|
+
quietHoursEnd: normalizeTimeInput(input.quietHoursEnd),
|
|
232
|
+
quietHoursStart: normalizeTimeInput(input.quietHoursStart),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async createTaskAssignedNotification({
|
|
237
|
+
instance,
|
|
238
|
+
manager,
|
|
239
|
+
node,
|
|
240
|
+
task,
|
|
241
|
+
transferred = false,
|
|
242
|
+
}: {
|
|
243
|
+
readonly instance: ApprovalInstanceEntity;
|
|
244
|
+
readonly manager: EntityManager;
|
|
245
|
+
readonly node: UserTaskNode;
|
|
246
|
+
readonly task: TaskEntity;
|
|
247
|
+
readonly transferred?: boolean;
|
|
248
|
+
}): Promise<readonly NotificationEntity[]> {
|
|
249
|
+
if (!task.assigneeMemberId) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return this.createNotifications(
|
|
254
|
+
{
|
|
255
|
+
channels: readNodeNotificationChannels(node, this.notificationOptions),
|
|
256
|
+
customTemplate: node.data.notification?.customTemplate ?? null,
|
|
257
|
+
instanceId: instance.id,
|
|
258
|
+
payload: {
|
|
259
|
+
assigneeMemberId: task.assigneeMemberId,
|
|
260
|
+
instanceId: instance.id,
|
|
261
|
+
instanceTitle: instance.title,
|
|
262
|
+
nodeId: node.id,
|
|
263
|
+
nodeLabel: node.data.label,
|
|
264
|
+
originalAssigneeMemberId: task.originalAssigneeMemberId,
|
|
265
|
+
slaDueAt: task.slaDueAt?.toISOString() ?? null,
|
|
266
|
+
taskId: task.id,
|
|
267
|
+
},
|
|
268
|
+
recipientMemberId: task.assigneeMemberId,
|
|
269
|
+
taskId: task.id,
|
|
270
|
+
type: transferred
|
|
271
|
+
? NotificationTypeEnum.TASK_TRANSFERRED
|
|
272
|
+
: NotificationTypeEnum.TASK_ASSIGNED,
|
|
273
|
+
},
|
|
274
|
+
manager,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async createServiceTaskNotifications({
|
|
279
|
+
instance,
|
|
280
|
+
manager,
|
|
281
|
+
node,
|
|
282
|
+
recipientMemberIds,
|
|
283
|
+
}: {
|
|
284
|
+
readonly instance: ApprovalInstanceEntity;
|
|
285
|
+
readonly manager: EntityManager;
|
|
286
|
+
readonly node: ServiceTaskNode;
|
|
287
|
+
readonly recipientMemberIds: readonly string[];
|
|
288
|
+
}): Promise<readonly NotificationEntity[]> {
|
|
289
|
+
if (node.data.action.type !== 'NOTIFY') {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const action = node.data.action;
|
|
294
|
+
const channels = normalizeNotificationChannels(action.channels);
|
|
295
|
+
const uniqueRecipientMemberIds = uniqueStrings(recipientMemberIds);
|
|
296
|
+
|
|
297
|
+
return uniqueRecipientMemberIds.reduce<
|
|
298
|
+
Promise<readonly NotificationEntity[]>
|
|
299
|
+
>(
|
|
300
|
+
async (
|
|
301
|
+
previousPromise,
|
|
302
|
+
recipientMemberId,
|
|
303
|
+
): Promise<readonly NotificationEntity[]> => {
|
|
304
|
+
const previous = await previousPromise;
|
|
305
|
+
const created = await this.createNotifications(
|
|
306
|
+
{
|
|
307
|
+
channels,
|
|
308
|
+
customTemplate: action.template ?? null,
|
|
309
|
+
instanceId: instance.id,
|
|
310
|
+
payload: {
|
|
311
|
+
instanceId: instance.id,
|
|
312
|
+
instanceTitle: instance.title,
|
|
313
|
+
message:
|
|
314
|
+
action.template ??
|
|
315
|
+
`案件 ${instance.title} 的 ${node.data.label} 已送出通知。`,
|
|
316
|
+
nodeId: node.id,
|
|
317
|
+
nodeLabel: node.data.label,
|
|
318
|
+
recipientMemberId,
|
|
319
|
+
},
|
|
320
|
+
recipientMemberId,
|
|
321
|
+
taskId: null,
|
|
322
|
+
type: NotificationTypeEnum.WORKFLOW_NOTIFICATION,
|
|
323
|
+
},
|
|
324
|
+
manager,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
return [...previous, ...created];
|
|
328
|
+
},
|
|
329
|
+
Promise.resolve([]),
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Deliver an ad-hoc directive notification (STAGE_NOTIFY /
|
|
335
|
+
* COMPLETION_NOTIFY) to resolved member recipients. Runs inside the
|
|
336
|
+
* caller's transaction `manager` so it commits atomically with the
|
|
337
|
+
* workflow state change that triggered it.
|
|
338
|
+
*/
|
|
339
|
+
async createAdhocWorkflowNotifications({
|
|
340
|
+
channels,
|
|
341
|
+
instance,
|
|
342
|
+
manager,
|
|
343
|
+
message,
|
|
344
|
+
payload,
|
|
345
|
+
recipientMemberIds,
|
|
346
|
+
}: {
|
|
347
|
+
readonly channels: readonly NotificationChannelEnum[] | null;
|
|
348
|
+
readonly instance: ApprovalInstanceEntity;
|
|
349
|
+
readonly manager: EntityManager;
|
|
350
|
+
readonly message: string;
|
|
351
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
352
|
+
readonly recipientMemberIds: readonly string[];
|
|
353
|
+
}): Promise<readonly NotificationEntity[]> {
|
|
354
|
+
const normalizedChannels = channels?.length
|
|
355
|
+
? channels
|
|
356
|
+
: [NotificationChannelEnum.IN_APP];
|
|
357
|
+
const uniqueRecipientMemberIds = uniqueStrings(recipientMemberIds);
|
|
358
|
+
|
|
359
|
+
return uniqueRecipientMemberIds.reduce<
|
|
360
|
+
Promise<readonly NotificationEntity[]>
|
|
361
|
+
>(
|
|
362
|
+
async (
|
|
363
|
+
previousPromise,
|
|
364
|
+
recipientMemberId,
|
|
365
|
+
): Promise<readonly NotificationEntity[]> => {
|
|
366
|
+
const previous = await previousPromise;
|
|
367
|
+
const created = await this.createNotifications(
|
|
368
|
+
{
|
|
369
|
+
channels: normalizedChannels,
|
|
370
|
+
instanceId: instance.id,
|
|
371
|
+
payload: {
|
|
372
|
+
...payload,
|
|
373
|
+
instanceId: instance.id,
|
|
374
|
+
instanceTitle: instance.title,
|
|
375
|
+
message,
|
|
376
|
+
recipientMemberId,
|
|
377
|
+
},
|
|
378
|
+
recipientMemberId,
|
|
379
|
+
taskId: null,
|
|
380
|
+
type: NotificationTypeEnum.WORKFLOW_NOTIFICATION,
|
|
381
|
+
},
|
|
382
|
+
manager,
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
return [...previous, ...created];
|
|
386
|
+
},
|
|
387
|
+
Promise.resolve([]),
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
async createInstanceCompletedNotification({
|
|
392
|
+
instance,
|
|
393
|
+
manager,
|
|
394
|
+
}: {
|
|
395
|
+
readonly instance: ApprovalInstanceEntity;
|
|
396
|
+
readonly manager: EntityManager;
|
|
397
|
+
}): Promise<readonly NotificationEntity[]> {
|
|
398
|
+
const repository = manager.getRepository(NotificationEntity);
|
|
399
|
+
const existingNotification = await repository.findOne({
|
|
400
|
+
where: {
|
|
401
|
+
channel: NotificationChannelEnum.IN_APP,
|
|
402
|
+
instanceId: instance.id,
|
|
403
|
+
recipientMemberId: instance.initiatorMemberId,
|
|
404
|
+
taskId: IsNull(),
|
|
405
|
+
type: NotificationTypeEnum.INSTANCE_COMPLETED,
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
if (existingNotification) {
|
|
410
|
+
return [];
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return this.createNotifications(
|
|
414
|
+
{
|
|
415
|
+
channels: [NotificationChannelEnum.IN_APP],
|
|
416
|
+
instanceId: instance.id,
|
|
417
|
+
payload: {
|
|
418
|
+
completedAt: instance.completedAt?.toISOString() ?? null,
|
|
419
|
+
instanceId: instance.id,
|
|
420
|
+
instanceTitle: instance.title,
|
|
421
|
+
recipientMemberId: instance.initiatorMemberId,
|
|
422
|
+
},
|
|
423
|
+
recipientMemberId: instance.initiatorMemberId,
|
|
424
|
+
taskId: null,
|
|
425
|
+
type: NotificationTypeEnum.INSTANCE_COMPLETED,
|
|
426
|
+
},
|
|
427
|
+
manager,
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Resolve the open task-assignment notifications for a decided task, so the
|
|
433
|
+
* inline 同意/拒絕 actions stop being offered once the task no longer needs
|
|
434
|
+
* the recipient. The acting member's notification records the actual
|
|
435
|
+
* decision (`resolution`); every other candidate's notification is marked
|
|
436
|
+
* `SUPERSEDED` when the task has ended. Runs inside the caller's
|
|
437
|
+
* transaction `manager` so it commits atomically with the decision.
|
|
438
|
+
*/
|
|
439
|
+
async resolveTaskNotifications({
|
|
440
|
+
actingMemberId,
|
|
441
|
+
manager,
|
|
442
|
+
resolution,
|
|
443
|
+
supersedeOthers,
|
|
444
|
+
taskId,
|
|
445
|
+
}: {
|
|
446
|
+
readonly actingMemberId: string;
|
|
447
|
+
readonly manager: EntityManager;
|
|
448
|
+
readonly resolution: NotificationResolutionEnum;
|
|
449
|
+
readonly supersedeOthers: boolean;
|
|
450
|
+
readonly taskId: string;
|
|
451
|
+
}): Promise<void> {
|
|
452
|
+
const repository = manager.getRepository(NotificationEntity);
|
|
453
|
+
const resolvedAt = new Date();
|
|
454
|
+
|
|
455
|
+
await repository.update(
|
|
456
|
+
{
|
|
457
|
+
recipientMemberId: actingMemberId,
|
|
458
|
+
resolvedAt: IsNull(),
|
|
459
|
+
taskId,
|
|
460
|
+
type: In(ACTIONABLE_NOTIFICATION_TYPES),
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
readAt: resolvedAt,
|
|
464
|
+
resolution,
|
|
465
|
+
resolvedAt,
|
|
466
|
+
status: NotificationStatusEnum.READ,
|
|
467
|
+
},
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
if (supersedeOthers) {
|
|
471
|
+
await repository.update(
|
|
472
|
+
{
|
|
473
|
+
recipientMemberId: Not(actingMemberId),
|
|
474
|
+
resolvedAt: IsNull(),
|
|
475
|
+
taskId,
|
|
476
|
+
type: In(ACTIONABLE_NOTIFICATION_TYPES),
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
readAt: resolvedAt,
|
|
480
|
+
resolution: NotificationResolutionEnum.SUPERSEDED,
|
|
481
|
+
resolvedAt,
|
|
482
|
+
status: NotificationStatusEnum.READ,
|
|
483
|
+
},
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Mark every still-open task-assignment notification for an instance as
|
|
490
|
+
* `SUPERSEDED` — used when the whole instance is cancelled, so lingering
|
|
491
|
+
* "待簽" notifications can no longer be actioned. Runs inside the caller's
|
|
492
|
+
* transaction `manager`.
|
|
493
|
+
*/
|
|
494
|
+
async supersedeInstanceTaskNotifications({
|
|
495
|
+
instanceId,
|
|
496
|
+
manager,
|
|
497
|
+
}: {
|
|
498
|
+
readonly instanceId: string;
|
|
499
|
+
readonly manager: EntityManager;
|
|
500
|
+
}): Promise<void> {
|
|
501
|
+
const repository = manager.getRepository(NotificationEntity);
|
|
502
|
+
const resolvedAt = new Date();
|
|
503
|
+
|
|
504
|
+
await repository.update(
|
|
505
|
+
{
|
|
506
|
+
instanceId,
|
|
507
|
+
resolvedAt: IsNull(),
|
|
508
|
+
type: In(ACTIONABLE_NOTIFICATION_TYPES),
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
readAt: resolvedAt,
|
|
512
|
+
resolution: NotificationResolutionEnum.SUPERSEDED,
|
|
513
|
+
resolvedAt,
|
|
514
|
+
status: NotificationStatusEnum.READ,
|
|
515
|
+
},
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
async runSlaScan(now: Date = new Date()): Promise<SlaScanResult> {
|
|
520
|
+
const candidateTasks = await this.taskRepository.find({
|
|
521
|
+
order: { slaDueAt: 'ASC' },
|
|
522
|
+
where: [
|
|
523
|
+
{
|
|
524
|
+
slaDueAt: LessThanOrEqual(now),
|
|
525
|
+
status: TaskStatusEnum.PENDING,
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
slaDueAt: LessThanOrEqual(now),
|
|
529
|
+
status: TaskStatusEnum.IN_PROGRESS,
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
slaDueAt: MoreThan(now),
|
|
533
|
+
status: TaskStatusEnum.PENDING,
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
slaDueAt: MoreThan(now),
|
|
537
|
+
status: TaskStatusEnum.IN_PROGRESS,
|
|
538
|
+
},
|
|
539
|
+
],
|
|
540
|
+
});
|
|
541
|
+
const results = await candidateTasks.reduce<Promise<SlaScanResult>>(
|
|
542
|
+
async (resultPromise, task): Promise<SlaScanResult> => {
|
|
543
|
+
const currentResult = await resultPromise;
|
|
544
|
+
|
|
545
|
+
if (!(await this.tryClaimSlaTask(task.id))) {
|
|
546
|
+
return currentResult;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const instance = await this.approvalInstanceRepository.findOne({
|
|
550
|
+
where: { id: task.instanceId },
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
if (!instance) {
|
|
554
|
+
return currentResult;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const node = readUserTaskNode(instance, task.nodeId);
|
|
558
|
+
|
|
559
|
+
if (!node?.data.sla || !task.slaDueAt) {
|
|
560
|
+
return currentResult;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (task.slaDueAt.getTime() <= now.getTime()) {
|
|
564
|
+
const created = await this.createSlaNotificationOnce({
|
|
565
|
+
instance,
|
|
566
|
+
node,
|
|
567
|
+
task,
|
|
568
|
+
type: NotificationTypeEnum.SLA_OVERDUE,
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
if (created) {
|
|
572
|
+
await this.recordSlaActivity({
|
|
573
|
+
instance,
|
|
574
|
+
node,
|
|
575
|
+
task,
|
|
576
|
+
trigger: 'OVERDUE',
|
|
577
|
+
});
|
|
578
|
+
await this.runSlaTimeoutHook({ instance, node, task });
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return {
|
|
582
|
+
overdueCount: currentResult.overdueCount + (created ? 1 : 0),
|
|
583
|
+
warningCount: currentResult.warningCount,
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const warningAt = node.data.sla.warningAt;
|
|
588
|
+
|
|
589
|
+
if (!warningAt || warningAt <= 0 || warningAt >= 1) {
|
|
590
|
+
return currentResult;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const warningAtTime =
|
|
594
|
+
task.createdAt.getTime() +
|
|
595
|
+
(task.slaDueAt.getTime() - task.createdAt.getTime()) * warningAt;
|
|
596
|
+
|
|
597
|
+
if (warningAtTime > now.getTime()) {
|
|
598
|
+
return currentResult;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const created = await this.createSlaNotificationOnce({
|
|
602
|
+
instance,
|
|
603
|
+
node,
|
|
604
|
+
task,
|
|
605
|
+
type: NotificationTypeEnum.SLA_WARNING,
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
if (created) {
|
|
609
|
+
await this.recordSlaActivity({
|
|
610
|
+
instance,
|
|
611
|
+
node,
|
|
612
|
+
task,
|
|
613
|
+
trigger: 'WARNING',
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
overdueCount: currentResult.overdueCount,
|
|
619
|
+
warningCount: currentResult.warningCount + (created ? 1 : 0),
|
|
620
|
+
};
|
|
621
|
+
},
|
|
622
|
+
Promise.resolve({ overdueCount: 0, warningCount: 0 }),
|
|
623
|
+
);
|
|
624
|
+
|
|
625
|
+
return results;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
private async tryClaimSlaTask(taskId: string): Promise<boolean> {
|
|
629
|
+
if (!this.taskRepository.query) {
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const rows = (await this.taskRepository.query(
|
|
634
|
+
'SELECT pg_try_advisory_xact_lock(hashtext($1)) AS claimed',
|
|
635
|
+
[`bpm-sla:${taskId}`],
|
|
636
|
+
)) as readonly { readonly claimed?: boolean }[];
|
|
637
|
+
|
|
638
|
+
return rows[0]?.claimed !== false;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
private async createSlaNotificationOnce({
|
|
642
|
+
instance,
|
|
643
|
+
node,
|
|
644
|
+
task,
|
|
645
|
+
type,
|
|
646
|
+
}: {
|
|
647
|
+
readonly instance: ApprovalInstanceEntity;
|
|
648
|
+
readonly node: UserTaskNode;
|
|
649
|
+
readonly task: TaskEntity;
|
|
650
|
+
readonly type:
|
|
651
|
+
| NotificationTypeEnum.SLA_OVERDUE
|
|
652
|
+
| NotificationTypeEnum.SLA_WARNING;
|
|
653
|
+
}): Promise<boolean> {
|
|
654
|
+
const recipientMemberIds = await this.resolveTaskRecipientMemberIds(task);
|
|
655
|
+
|
|
656
|
+
if (recipientMemberIds.length === 0) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const createdNotifications = await recipientMemberIds.reduce<
|
|
661
|
+
Promise<number>
|
|
662
|
+
>(async (countPromise, recipientMemberId): Promise<number> => {
|
|
663
|
+
const count = await countPromise;
|
|
664
|
+
const existingNotification = await this.notificationRepository.findOne({
|
|
665
|
+
where: {
|
|
666
|
+
channel: NotificationChannelEnum.IN_APP,
|
|
667
|
+
recipientMemberId,
|
|
668
|
+
taskId: task.id,
|
|
669
|
+
type,
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
if (existingNotification) {
|
|
674
|
+
return count;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
try {
|
|
678
|
+
await this.createNotifications({
|
|
679
|
+
channels: [NotificationChannelEnum.IN_APP],
|
|
680
|
+
customTemplate: node.data.notification?.customTemplate ?? null,
|
|
681
|
+
instanceId: instance.id,
|
|
682
|
+
payload: {
|
|
683
|
+
assigneeMemberId: task.assigneeMemberId,
|
|
684
|
+
instanceId: instance.id,
|
|
685
|
+
instanceTitle: instance.title,
|
|
686
|
+
nodeId: node.id,
|
|
687
|
+
nodeLabel: node.data.label,
|
|
688
|
+
onTimeout: node.data.sla?.onTimeout ?? 'REMIND',
|
|
689
|
+
recipientMemberId,
|
|
690
|
+
slaDueAt: task.slaDueAt?.toISOString() ?? null,
|
|
691
|
+
taskId: task.id,
|
|
692
|
+
},
|
|
693
|
+
recipientMemberId,
|
|
694
|
+
taskId: task.id,
|
|
695
|
+
type,
|
|
696
|
+
});
|
|
697
|
+
} catch (error: unknown) {
|
|
698
|
+
if (isUniqueConstraintViolation(error)) {
|
|
699
|
+
return count;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
throw error;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return count + 1;
|
|
706
|
+
}, Promise.resolve(0));
|
|
707
|
+
|
|
708
|
+
return createdNotifications > 0;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
private async createNotifications(
|
|
712
|
+
input: CreateNotificationInput,
|
|
713
|
+
manager?: EntityManager,
|
|
714
|
+
): Promise<readonly NotificationEntity[]> {
|
|
715
|
+
const preference = await this.getPreference(input.recipientMemberId);
|
|
716
|
+
const repository = manager
|
|
717
|
+
? manager.getRepository(NotificationEntity)
|
|
718
|
+
: this.notificationRepository;
|
|
719
|
+
const notifications = input.channels.flatMap((channel) =>
|
|
720
|
+
isChannelEnabled(channel, preference, this.notificationOptions)
|
|
721
|
+
? [
|
|
722
|
+
createNotificationEntity({
|
|
723
|
+
channel,
|
|
724
|
+
input,
|
|
725
|
+
options: this.notificationOptions,
|
|
726
|
+
repository,
|
|
727
|
+
}),
|
|
728
|
+
]
|
|
729
|
+
: [],
|
|
730
|
+
);
|
|
731
|
+
|
|
732
|
+
if (notifications.length === 0) {
|
|
733
|
+
return [];
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const savedNotifications = await repository.save(notifications);
|
|
737
|
+
|
|
738
|
+
await Promise.all(
|
|
739
|
+
savedNotifications
|
|
740
|
+
.filter(
|
|
741
|
+
(notification) =>
|
|
742
|
+
notification.channel !== NotificationChannelEnum.IN_APP,
|
|
743
|
+
)
|
|
744
|
+
.map((notification) =>
|
|
745
|
+
manager
|
|
746
|
+
? Promise.resolve(false)
|
|
747
|
+
: this.deliveryService.deliverNotification(
|
|
748
|
+
notification,
|
|
749
|
+
this.notificationOptions,
|
|
750
|
+
),
|
|
751
|
+
),
|
|
752
|
+
);
|
|
753
|
+
|
|
754
|
+
return savedNotifications;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
private async recordSlaActivity({
|
|
758
|
+
instance,
|
|
759
|
+
node,
|
|
760
|
+
task,
|
|
761
|
+
trigger,
|
|
762
|
+
}: {
|
|
763
|
+
readonly instance: ApprovalInstanceEntity;
|
|
764
|
+
readonly node: UserTaskNode;
|
|
765
|
+
readonly task: TaskEntity;
|
|
766
|
+
readonly trigger: 'OVERDUE' | 'WARNING';
|
|
767
|
+
}): Promise<void> {
|
|
768
|
+
await this.activityLogRepository.save(
|
|
769
|
+
this.activityLogRepository.create({
|
|
770
|
+
actorMemberId: null,
|
|
771
|
+
eventType: ActivityLogEventTypeEnum.SLA_TRIGGERED,
|
|
772
|
+
instanceId: instance.id,
|
|
773
|
+
nodeId: task.nodeId,
|
|
774
|
+
payload: {
|
|
775
|
+
assigneeMemberId: task.assigneeMemberId,
|
|
776
|
+
nodeLabel: node.data.label,
|
|
777
|
+
onTimeout: node.data.sla?.onTimeout ?? 'REMIND',
|
|
778
|
+
slaDueAt: task.slaDueAt?.toISOString() ?? null,
|
|
779
|
+
trigger,
|
|
780
|
+
},
|
|
781
|
+
taskId: task.id,
|
|
782
|
+
}),
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
private async runSlaTimeoutHook({
|
|
787
|
+
instance,
|
|
788
|
+
node,
|
|
789
|
+
task,
|
|
790
|
+
}: {
|
|
791
|
+
readonly instance: ApprovalInstanceEntity;
|
|
792
|
+
readonly node: UserTaskNode;
|
|
793
|
+
readonly task: TaskEntity;
|
|
794
|
+
}): Promise<void> {
|
|
795
|
+
const timeoutAction = node.data.sla?.onTimeout ?? 'REMIND';
|
|
796
|
+
|
|
797
|
+
if (!isSlaTimeoutActionEnabled(timeoutAction, this.notificationOptions)) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
await this.executeSlaTimeoutAction({
|
|
802
|
+
instance,
|
|
803
|
+
node,
|
|
804
|
+
task,
|
|
805
|
+
timeoutAction,
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
private async executeSlaTimeoutAction({
|
|
810
|
+
instance,
|
|
811
|
+
node,
|
|
812
|
+
task,
|
|
813
|
+
timeoutAction,
|
|
814
|
+
}: {
|
|
815
|
+
readonly instance: ApprovalInstanceEntity;
|
|
816
|
+
readonly node: UserTaskNode;
|
|
817
|
+
readonly task: TaskEntity;
|
|
818
|
+
readonly timeoutAction: NonNullable<
|
|
819
|
+
UserTaskNode['data']['sla']
|
|
820
|
+
>['onTimeout'];
|
|
821
|
+
}): Promise<void> {
|
|
822
|
+
if (timeoutAction === 'REMIND') {
|
|
823
|
+
this.logger.log(`SLA reminder processed for task ${task.id}`);
|
|
824
|
+
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const workflowEngine = this.moduleRef.get<BPMWorkflowEngineService>(
|
|
829
|
+
BPM_WORKFLOW_ENGINE_SERVICE,
|
|
830
|
+
{ strict: false },
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
if (timeoutAction === 'AUTO_APPROVE') {
|
|
834
|
+
const actorMemberId = await this.resolveTaskActorMemberId(task);
|
|
835
|
+
|
|
836
|
+
await workflowEngine.decideTask({
|
|
837
|
+
action: TaskDecisionActionEnum.APPROVED,
|
|
838
|
+
comment: 'SLA timeout auto-approved this task.',
|
|
839
|
+
decidedByMemberId: actorMemberId,
|
|
840
|
+
taskId: task.id,
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
if (timeoutAction === 'ESCALATE') {
|
|
847
|
+
const actorMemberId = await this.resolveTaskActorMemberId(task);
|
|
848
|
+
const targetMemberId = await this.resolveEscalationTargetMemberId({
|
|
849
|
+
actorMemberId,
|
|
850
|
+
node,
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
if (!targetMemberId || targetMemberId === actorMemberId) {
|
|
854
|
+
this.logger.warn(`SLA escalation skipped for task ${task.id}`);
|
|
855
|
+
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
await workflowEngine.decideTask({
|
|
860
|
+
action: TaskDecisionActionEnum.TRANSFERRED,
|
|
861
|
+
comment: 'SLA timeout escalated this task.',
|
|
862
|
+
decidedByMemberId: actorMemberId,
|
|
863
|
+
taskId: task.id,
|
|
864
|
+
transferToMemberId: targetMemberId,
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
await workflowEngine.cancelApprovalInstance({
|
|
871
|
+
cancelledByMemberId: instance.initiatorMemberId,
|
|
872
|
+
comment: 'SLA timeout terminated this instance.',
|
|
873
|
+
instanceId: instance.id,
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
private async resolveTaskActorMemberId(task: TaskEntity): Promise<string> {
|
|
878
|
+
if (task.assigneeMemberId) {
|
|
879
|
+
return task.assigneeMemberId;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const candidate = await this.taskCandidateRepository.findOne({
|
|
883
|
+
order: { createdAt: 'ASC' },
|
|
884
|
+
where: { taskId: task.id },
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
if (!candidate) {
|
|
888
|
+
throw new NotFoundException(`Task ${task.id} has no actor candidate`);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
return candidate.memberId;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
private async resolveTaskRecipientMemberIds(
|
|
895
|
+
task: TaskEntity,
|
|
896
|
+
): Promise<readonly string[]> {
|
|
897
|
+
if (task.assigneeMemberId) {
|
|
898
|
+
return [task.assigneeMemberId];
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
const candidates = await this.taskCandidateRepository.find({
|
|
902
|
+
order: { createdAt: 'ASC' },
|
|
903
|
+
where: { taskId: task.id },
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
return uniqueStrings(
|
|
907
|
+
candidates
|
|
908
|
+
.filter(
|
|
909
|
+
(candidate) =>
|
|
910
|
+
candidate.status === TaskCandidateStatusEnum.PENDING ||
|
|
911
|
+
candidate.status === TaskCandidateStatusEnum.CLAIMED,
|
|
912
|
+
)
|
|
913
|
+
.map((candidate) => candidate.memberId),
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
private async resolveEscalationTargetMemberId({
|
|
918
|
+
actorMemberId,
|
|
919
|
+
node,
|
|
920
|
+
}: {
|
|
921
|
+
readonly actorMemberId: string;
|
|
922
|
+
readonly node: UserTaskNode;
|
|
923
|
+
}): Promise<string | null> {
|
|
924
|
+
const organizationService = this.moduleRef.get(OrganizationService, {
|
|
925
|
+
strict: false,
|
|
926
|
+
});
|
|
927
|
+
const levelsUp = Math.max(node.data.sla?.escalateLevelsUp ?? 1, 1);
|
|
928
|
+
let currentMemberId: string | null = actorMemberId;
|
|
929
|
+
|
|
930
|
+
for (let level = 0; level < levelsUp && currentMemberId; level += 1) {
|
|
931
|
+
currentMemberId =
|
|
932
|
+
await organizationService.resolveManagerMemberId(currentMemberId);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
return currentMemberId;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
export function calculateTaskSlaDueAt({
|
|
940
|
+
node,
|
|
941
|
+
now,
|
|
942
|
+
}: {
|
|
943
|
+
readonly node: UserTaskNode;
|
|
944
|
+
readonly now: Date;
|
|
945
|
+
}): Date | null {
|
|
946
|
+
const duration = node.data.sla?.duration;
|
|
947
|
+
|
|
948
|
+
if (!duration) {
|
|
949
|
+
return null;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
const durationMs = parseIsoDurationToMilliseconds(duration);
|
|
953
|
+
|
|
954
|
+
return durationMs ? new Date(now.getTime() + durationMs) : null;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function createDefaultPreference(
|
|
958
|
+
memberId: string,
|
|
959
|
+
options: BPMResolvedNotificationOptions,
|
|
960
|
+
): NotificationPreferenceEntity {
|
|
961
|
+
return Object.assign(new NotificationPreferenceEntity(), {
|
|
962
|
+
emailDigestMode: options.defaultEmailDigestMode,
|
|
963
|
+
emailEnabled: options.defaultEmailPreferenceEnabled,
|
|
964
|
+
inAppEnabled: options.defaultInAppPreferenceEnabled,
|
|
965
|
+
memberId,
|
|
966
|
+
quietHoursEnd: null,
|
|
967
|
+
quietHoursStart: null,
|
|
968
|
+
updatedAt: new Date(0),
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function normalizeTimeInput(value: string | null): string | null {
|
|
973
|
+
const trimmedValue = value?.trim() ?? '';
|
|
974
|
+
|
|
975
|
+
return trimmedValue || null;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function readNodeNotificationChannels(
|
|
979
|
+
node: UserTaskNode,
|
|
980
|
+
options: BPMResolvedNotificationOptions,
|
|
981
|
+
): readonly NotificationChannelEnum[] {
|
|
982
|
+
const configuredChannels = node.data.notification?.channels ?? [];
|
|
983
|
+
const channels = configuredChannels
|
|
984
|
+
.map((channel): NotificationChannelEnum | null =>
|
|
985
|
+
channel === 'EMAIL'
|
|
986
|
+
? NotificationChannelEnum.EMAIL
|
|
987
|
+
: channel === 'WEBHOOK'
|
|
988
|
+
? NotificationChannelEnum.WEBHOOK
|
|
989
|
+
: channel === 'IN_APP'
|
|
990
|
+
? NotificationChannelEnum.IN_APP
|
|
991
|
+
: null,
|
|
992
|
+
)
|
|
993
|
+
.filter((channel): channel is NotificationChannelEnum => Boolean(channel));
|
|
994
|
+
|
|
995
|
+
return channels.length ? channels : options.defaultChannels;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function normalizeNotificationChannels(
|
|
999
|
+
channels: readonly string[],
|
|
1000
|
+
): readonly NotificationChannelEnum[] {
|
|
1001
|
+
const normalizedChannels = channels
|
|
1002
|
+
.map((channel): NotificationChannelEnum | null =>
|
|
1003
|
+
channel === NotificationChannelEnum.EMAIL
|
|
1004
|
+
? NotificationChannelEnum.EMAIL
|
|
1005
|
+
: channel === NotificationChannelEnum.IN_APP
|
|
1006
|
+
? NotificationChannelEnum.IN_APP
|
|
1007
|
+
: null,
|
|
1008
|
+
)
|
|
1009
|
+
.filter((channel): channel is NotificationChannelEnum => Boolean(channel));
|
|
1010
|
+
|
|
1011
|
+
return normalizedChannels.length
|
|
1012
|
+
? normalizedChannels
|
|
1013
|
+
: [NotificationChannelEnum.IN_APP];
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function uniqueStrings(values: readonly string[]): readonly string[] {
|
|
1017
|
+
return Array.from(new Set(values));
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
function isUniqueConstraintViolation(error: unknown): boolean {
|
|
1021
|
+
return (
|
|
1022
|
+
typeof error === 'object' &&
|
|
1023
|
+
error !== null &&
|
|
1024
|
+
'code' in error &&
|
|
1025
|
+
error.code === '23505'
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function isChannelEnabled(
|
|
1030
|
+
channel: NotificationChannelEnum,
|
|
1031
|
+
preference: NotificationPreferenceEntity,
|
|
1032
|
+
options: BPMResolvedNotificationOptions,
|
|
1033
|
+
): boolean {
|
|
1034
|
+
if (channel === NotificationChannelEnum.IN_APP) {
|
|
1035
|
+
return options.inAppEnabled && preference.inAppEnabled;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
if (channel === NotificationChannelEnum.EMAIL) {
|
|
1039
|
+
return options.emailEnabled && preference.emailEnabled;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
return options.webhookEnabled;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function isSlaTimeoutActionEnabled(
|
|
1046
|
+
action: NonNullable<UserTaskNode['data']['sla']>['onTimeout'],
|
|
1047
|
+
options: BPMResolvedNotificationOptions,
|
|
1048
|
+
): boolean {
|
|
1049
|
+
if (action === 'AUTO_APPROVE') {
|
|
1050
|
+
return options.slaTimeoutAutoApproveEnabled;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (action === 'ESCALATE') {
|
|
1054
|
+
return options.slaTimeoutEscalateEnabled;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
if (action === 'TERMINATE_INSTANCE') {
|
|
1058
|
+
return options.slaTimeoutTerminateInstanceEnabled;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
return options.slaTimeoutRemindEnabled;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
function createNotificationEntity({
|
|
1065
|
+
channel,
|
|
1066
|
+
input,
|
|
1067
|
+
options,
|
|
1068
|
+
repository,
|
|
1069
|
+
}: {
|
|
1070
|
+
readonly channel: NotificationChannelEnum;
|
|
1071
|
+
readonly input: CreateNotificationInput;
|
|
1072
|
+
readonly options: BPMResolvedNotificationOptions;
|
|
1073
|
+
readonly repository: Repository<NotificationEntity>;
|
|
1074
|
+
}): NotificationEntity {
|
|
1075
|
+
const renderedTemplate = renderNotificationTemplate({
|
|
1076
|
+
customTemplate: input.customTemplate,
|
|
1077
|
+
engine: options.templateEngine,
|
|
1078
|
+
payload: input.payload,
|
|
1079
|
+
type: input.type,
|
|
1080
|
+
});
|
|
1081
|
+
const isInApp = channel === NotificationChannelEnum.IN_APP;
|
|
1082
|
+
|
|
1083
|
+
return repository.create({
|
|
1084
|
+
attemptCount: 0,
|
|
1085
|
+
body: renderedTemplate.body,
|
|
1086
|
+
channel,
|
|
1087
|
+
deliveredAt: isInApp ? new Date() : null,
|
|
1088
|
+
deliveryError: null,
|
|
1089
|
+
deliveryTarget: null,
|
|
1090
|
+
instanceId: input.instanceId,
|
|
1091
|
+
lastAttemptAt: null,
|
|
1092
|
+
nextRetryAt: null,
|
|
1093
|
+
payload: input.payload,
|
|
1094
|
+
readAt: null,
|
|
1095
|
+
recipientMemberId: input.recipientMemberId,
|
|
1096
|
+
resolution: null,
|
|
1097
|
+
resolvedAt: null,
|
|
1098
|
+
sentAt: isInApp ? new Date() : null,
|
|
1099
|
+
status: isInApp
|
|
1100
|
+
? NotificationStatusEnum.SENT
|
|
1101
|
+
: NotificationStatusEnum.PENDING,
|
|
1102
|
+
taskId: input.taskId,
|
|
1103
|
+
title: renderedTemplate.title,
|
|
1104
|
+
type: input.type,
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
function readUserTaskNode(
|
|
1109
|
+
instance: ApprovalInstanceEntity,
|
|
1110
|
+
nodeId: string,
|
|
1111
|
+
): UserTaskNode | null {
|
|
1112
|
+
const node = instance.workflowSnapshot.nodes.find(
|
|
1113
|
+
(candidate) => candidate.id === nodeId,
|
|
1114
|
+
);
|
|
1115
|
+
|
|
1116
|
+
return node?.type === 'userTask' ? node : null;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function normalizePage(page: number): number {
|
|
1120
|
+
return Number.isInteger(page) && page > 0 ? page : 1;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function normalizePageSize(pageSize: number): number {
|
|
1124
|
+
if (!Number.isInteger(pageSize)) {
|
|
1125
|
+
return 10;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
return Math.min(Math.max(pageSize, 1), 100);
|
|
1129
|
+
}
|