@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,822 @@
|
|
|
1
|
+
import { EntityManager, ObjectLiteral, Repository } from 'typeorm';
|
|
2
|
+
import { ConditionService } from '../condition/condition.service';
|
|
3
|
+
import { FormDefinitionEntity } from '../form/form-definition.entity';
|
|
4
|
+
import { FormDefinitionVersionEntity } from '../form/form-definition-version.entity';
|
|
5
|
+
import { FormDefinitionVersionStatusEnum } from '../form/form.enums';
|
|
6
|
+
import { FormService } from '../form/form.service';
|
|
7
|
+
import { ApprovalTemplateCategoryEntity } from './approval-template-category.entity';
|
|
8
|
+
import { ApprovalTemplateEntity } from './approval-template.entity';
|
|
9
|
+
import { ApprovalTemplateVersionEntity } from './approval-template-version.entity';
|
|
10
|
+
import {
|
|
11
|
+
ApprovalTemplateCategoryStatusEnum,
|
|
12
|
+
ApprovalTemplateListStatusEnum,
|
|
13
|
+
ApprovalTemplateVersionStatusEnum,
|
|
14
|
+
} from './template.enums';
|
|
15
|
+
import { TemplateService } from './template.service';
|
|
16
|
+
import { EMPTY_WORKFLOW_DEFINITION } from './workflow-definition.validator';
|
|
17
|
+
|
|
18
|
+
describe('TemplateService', () => {
|
|
19
|
+
it('applies backend pagination when listing approval templates and counts active records', async (): Promise<void> => {
|
|
20
|
+
const templates = Array.from({ length: 13 }, (_, index) =>
|
|
21
|
+
createApprovalTemplate(`template-${index + 1}`),
|
|
22
|
+
);
|
|
23
|
+
const find = jest.fn(
|
|
24
|
+
({
|
|
25
|
+
skip = 0,
|
|
26
|
+
take = 10,
|
|
27
|
+
}: {
|
|
28
|
+
readonly skip?: number;
|
|
29
|
+
readonly take?: number;
|
|
30
|
+
}): Promise<readonly ApprovalTemplateEntity[]> =>
|
|
31
|
+
Promise.resolve(templates.slice(skip, skip + take)),
|
|
32
|
+
);
|
|
33
|
+
const count = jest.fn(
|
|
34
|
+
(): Promise<number> => Promise.resolve(templates.length),
|
|
35
|
+
);
|
|
36
|
+
const service = new TemplateService(
|
|
37
|
+
{
|
|
38
|
+
count,
|
|
39
|
+
find,
|
|
40
|
+
} as unknown as Repository<ApprovalTemplateEntity>,
|
|
41
|
+
createRepository<ApprovalTemplateCategoryEntity>(),
|
|
42
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
43
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
44
|
+
new ConditionService(),
|
|
45
|
+
{} as unknown as FormService,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const pageTwo = await service.listApprovalTemplates({
|
|
49
|
+
page: 2,
|
|
50
|
+
pageSize: 5,
|
|
51
|
+
});
|
|
52
|
+
const totalCount = await service.countApprovalTemplates();
|
|
53
|
+
|
|
54
|
+
expect(find).toHaveBeenCalledWith(
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
order: { createdAt: 'DESC', updatedAt: 'DESC' },
|
|
57
|
+
skip: 5,
|
|
58
|
+
take: 5,
|
|
59
|
+
where: expect.objectContaining({
|
|
60
|
+
deletedAt: expect.any(Object),
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
expect(pageTwo.map((template) => template.id)).toEqual([
|
|
65
|
+
'template-6',
|
|
66
|
+
'template-7',
|
|
67
|
+
'template-8',
|
|
68
|
+
'template-9',
|
|
69
|
+
'template-10',
|
|
70
|
+
]);
|
|
71
|
+
expect(totalCount).toBe(13);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('filters approval templates by derived publication status', async (): Promise<void> => {
|
|
75
|
+
const find = jest.fn(
|
|
76
|
+
(): Promise<readonly ApprovalTemplateEntity[]> => Promise.resolve([]),
|
|
77
|
+
);
|
|
78
|
+
const count = jest.fn((): Promise<number> => Promise.resolve(0));
|
|
79
|
+
const service = new TemplateService(
|
|
80
|
+
{
|
|
81
|
+
count,
|
|
82
|
+
find,
|
|
83
|
+
} as unknown as Repository<ApprovalTemplateEntity>,
|
|
84
|
+
createRepository<ApprovalTemplateCategoryEntity>(),
|
|
85
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
86
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
87
|
+
new ConditionService(),
|
|
88
|
+
{} as unknown as FormService,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
await service.listApprovalTemplates({
|
|
92
|
+
status: ApprovalTemplateListStatusEnum.PUBLISHED,
|
|
93
|
+
});
|
|
94
|
+
await service.countApprovalTemplates({
|
|
95
|
+
status: ApprovalTemplateListStatusEnum.DRAFT,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(find).toHaveBeenCalledWith(
|
|
99
|
+
expect.objectContaining({
|
|
100
|
+
where: expect.objectContaining({
|
|
101
|
+
currentVersionId: expect.any(Object),
|
|
102
|
+
deletedAt: expect.any(Object),
|
|
103
|
+
}),
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
expect(count).toHaveBeenCalledWith(
|
|
107
|
+
expect.objectContaining({
|
|
108
|
+
where: expect.objectContaining({
|
|
109
|
+
currentVersionId: expect.any(Object),
|
|
110
|
+
deletedAt: expect.any(Object),
|
|
111
|
+
}),
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('pushes search text into server-side template filters', async (): Promise<void> => {
|
|
117
|
+
const find = jest.fn(
|
|
118
|
+
(): Promise<readonly ApprovalTemplateEntity[]> => Promise.resolve([]),
|
|
119
|
+
);
|
|
120
|
+
const count = jest.fn((): Promise<number> => Promise.resolve(0));
|
|
121
|
+
const service = new TemplateService(
|
|
122
|
+
{
|
|
123
|
+
count,
|
|
124
|
+
find,
|
|
125
|
+
} as unknown as Repository<ApprovalTemplateEntity>,
|
|
126
|
+
createRepository<ApprovalTemplateCategoryEntity>(),
|
|
127
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
128
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
129
|
+
new ConditionService(),
|
|
130
|
+
{} as unknown as FormService,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
await service.listApprovalTemplates({
|
|
134
|
+
searchText: '費用',
|
|
135
|
+
status: ApprovalTemplateListStatusEnum.PUBLISHED,
|
|
136
|
+
});
|
|
137
|
+
await service.countApprovalTemplates({
|
|
138
|
+
searchText: '費用',
|
|
139
|
+
status: ApprovalTemplateListStatusEnum.PUBLISHED,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
expect(find).toHaveBeenCalledWith(
|
|
143
|
+
expect.objectContaining({
|
|
144
|
+
where: expect.arrayContaining([
|
|
145
|
+
expect.objectContaining({
|
|
146
|
+
currentVersionId: expect.any(Object),
|
|
147
|
+
deletedAt: expect.any(Object),
|
|
148
|
+
name: expect.any(Object),
|
|
149
|
+
}),
|
|
150
|
+
expect.objectContaining({
|
|
151
|
+
category: expect.any(Object),
|
|
152
|
+
currentVersionId: expect.any(Object),
|
|
153
|
+
deletedAt: expect.any(Object),
|
|
154
|
+
}),
|
|
155
|
+
expect.objectContaining({
|
|
156
|
+
currentVersionId: expect.any(Object),
|
|
157
|
+
deletedAt: expect.any(Object),
|
|
158
|
+
description: expect.any(Object),
|
|
159
|
+
}),
|
|
160
|
+
]),
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
expect(count).toHaveBeenCalledWith(
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
where: expect.any(Array),
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('filters approval templates by category id', async (): Promise<void> => {
|
|
171
|
+
const find = jest.fn(
|
|
172
|
+
(): Promise<readonly ApprovalTemplateEntity[]> => Promise.resolve([]),
|
|
173
|
+
);
|
|
174
|
+
const count = jest.fn((): Promise<number> => Promise.resolve(0));
|
|
175
|
+
const service = new TemplateService(
|
|
176
|
+
{
|
|
177
|
+
count,
|
|
178
|
+
find,
|
|
179
|
+
} as unknown as Repository<ApprovalTemplateEntity>,
|
|
180
|
+
createRepository<ApprovalTemplateCategoryEntity>(),
|
|
181
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
182
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
183
|
+
new ConditionService(),
|
|
184
|
+
{} as unknown as FormService,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
await service.listApprovalTemplates({
|
|
188
|
+
categoryId: 'category-1',
|
|
189
|
+
});
|
|
190
|
+
await service.countApprovalTemplates({
|
|
191
|
+
categoryId: 'category-1',
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(find).toHaveBeenCalledWith(
|
|
195
|
+
expect.objectContaining({
|
|
196
|
+
where: expect.objectContaining({
|
|
197
|
+
categoryId: 'category-1',
|
|
198
|
+
deletedAt: expect.any(Object),
|
|
199
|
+
}),
|
|
200
|
+
}),
|
|
201
|
+
);
|
|
202
|
+
expect(count).toHaveBeenCalledWith(
|
|
203
|
+
expect.objectContaining({
|
|
204
|
+
where: expect.objectContaining({
|
|
205
|
+
categoryId: 'category-1',
|
|
206
|
+
deletedAt: expect.any(Object),
|
|
207
|
+
}),
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('lists active approval template categories by default', async (): Promise<void> => {
|
|
213
|
+
const find = jest.fn(
|
|
214
|
+
(): Promise<readonly ApprovalTemplateCategoryEntity[]> =>
|
|
215
|
+
Promise.resolve([]),
|
|
216
|
+
);
|
|
217
|
+
const count = jest.fn((): Promise<number> => Promise.resolve(0));
|
|
218
|
+
const service = new TemplateService(
|
|
219
|
+
createRepository<ApprovalTemplateEntity>(),
|
|
220
|
+
{
|
|
221
|
+
count,
|
|
222
|
+
find,
|
|
223
|
+
} as unknown as Repository<ApprovalTemplateCategoryEntity>,
|
|
224
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
225
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
226
|
+
new ConditionService(),
|
|
227
|
+
{} as unknown as FormService,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
await service.listApprovalTemplateCategories({
|
|
231
|
+
page: 1,
|
|
232
|
+
pageSize: 20,
|
|
233
|
+
searchText: '財務',
|
|
234
|
+
});
|
|
235
|
+
await service.countApprovalTemplateCategories({
|
|
236
|
+
status: ApprovalTemplateCategoryStatusEnum.ALL,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(find).toHaveBeenCalledWith(
|
|
240
|
+
expect.objectContaining({
|
|
241
|
+
order: { createdAt: 'ASC', name: 'ASC', sortOrder: 'ASC' },
|
|
242
|
+
take: 20,
|
|
243
|
+
where: expect.arrayContaining([
|
|
244
|
+
expect.objectContaining({
|
|
245
|
+
isActive: true,
|
|
246
|
+
name: expect.any(Object),
|
|
247
|
+
}),
|
|
248
|
+
expect.objectContaining({
|
|
249
|
+
description: expect.any(Object),
|
|
250
|
+
isActive: true,
|
|
251
|
+
}),
|
|
252
|
+
]),
|
|
253
|
+
}),
|
|
254
|
+
);
|
|
255
|
+
expect(count).toHaveBeenCalledWith(
|
|
256
|
+
expect.objectContaining({
|
|
257
|
+
where: {},
|
|
258
|
+
}),
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('validates category existence when creating approval templates', async (): Promise<void> => {
|
|
263
|
+
const category = createApprovalTemplateCategory('category-1');
|
|
264
|
+
const categoryFindOne = jest.fn(
|
|
265
|
+
(): Promise<ApprovalTemplateCategoryEntity | null> =>
|
|
266
|
+
Promise.resolve(category),
|
|
267
|
+
);
|
|
268
|
+
const templateCreate = jest.fn(
|
|
269
|
+
(value: Partial<ApprovalTemplateEntity>): ApprovalTemplateEntity =>
|
|
270
|
+
Object.assign(new ApprovalTemplateEntity(), value),
|
|
271
|
+
);
|
|
272
|
+
const templateSave = jest.fn(
|
|
273
|
+
(value: ApprovalTemplateEntity): Promise<ApprovalTemplateEntity> =>
|
|
274
|
+
Promise.resolve({ ...value, id: 'template-1' }),
|
|
275
|
+
);
|
|
276
|
+
const versionSave = jest.fn(
|
|
277
|
+
(
|
|
278
|
+
value: ApprovalTemplateVersionEntity,
|
|
279
|
+
): Promise<ApprovalTemplateVersionEntity> => Promise.resolve(value),
|
|
280
|
+
);
|
|
281
|
+
const versionCreate = jest.fn(
|
|
282
|
+
(
|
|
283
|
+
value: Partial<ApprovalTemplateVersionEntity>,
|
|
284
|
+
): ApprovalTemplateVersionEntity =>
|
|
285
|
+
Object.assign(new ApprovalTemplateVersionEntity(), value),
|
|
286
|
+
);
|
|
287
|
+
const manager = {
|
|
288
|
+
getRepository: jest.fn((entity: unknown): unknown => {
|
|
289
|
+
if (entity === ApprovalTemplateEntity) {
|
|
290
|
+
return {
|
|
291
|
+
create: templateCreate,
|
|
292
|
+
save: templateSave,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (entity === ApprovalTemplateCategoryEntity) {
|
|
297
|
+
return {
|
|
298
|
+
findOne: categoryFindOne,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (entity === FormDefinitionVersionEntity) {
|
|
303
|
+
return {
|
|
304
|
+
findOne: jest.fn(
|
|
305
|
+
(): Promise<FormDefinitionVersionEntity | null> =>
|
|
306
|
+
Promise.resolve(null),
|
|
307
|
+
),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
create: versionCreate,
|
|
313
|
+
save: versionSave,
|
|
314
|
+
};
|
|
315
|
+
}),
|
|
316
|
+
transaction: jest.fn(
|
|
317
|
+
<TResult>(
|
|
318
|
+
operation: (manager: {
|
|
319
|
+
readonly getRepository: (entity: unknown) => unknown;
|
|
320
|
+
}) => Promise<TResult>,
|
|
321
|
+
): Promise<TResult> => operation(manager),
|
|
322
|
+
),
|
|
323
|
+
};
|
|
324
|
+
const service = new TemplateService(
|
|
325
|
+
{ manager } as unknown as Repository<ApprovalTemplateEntity>,
|
|
326
|
+
createRepository<ApprovalTemplateCategoryEntity>(),
|
|
327
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
328
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
329
|
+
new ConditionService(),
|
|
330
|
+
{} as unknown as FormService,
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
await service.createApprovalTemplate({
|
|
334
|
+
category: null,
|
|
335
|
+
categoryId: 'category-1',
|
|
336
|
+
createdByMemberId: null,
|
|
337
|
+
description: null,
|
|
338
|
+
formDefinitionVersionId: null,
|
|
339
|
+
name: '費用簽核',
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
expect(categoryFindOne).toHaveBeenCalledWith({
|
|
343
|
+
where: { id: 'category-1' },
|
|
344
|
+
});
|
|
345
|
+
expect(templateCreate).toHaveBeenCalledWith(
|
|
346
|
+
expect.objectContaining({
|
|
347
|
+
category: '財務',
|
|
348
|
+
categoryId: 'category-1',
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('rejects publishing a draft with workflow lint errors before mutating template state', async (): Promise<void> => {
|
|
354
|
+
const draftVersion = Object.assign(new ApprovalTemplateVersionEntity(), {
|
|
355
|
+
archivedAt: null,
|
|
356
|
+
createdAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
357
|
+
formDefinitionVersionId: 'form-version-1',
|
|
358
|
+
id: 'template-version-1',
|
|
359
|
+
initiatorPolicyCel: null,
|
|
360
|
+
notificationConfig: null,
|
|
361
|
+
publishedAt: null,
|
|
362
|
+
publishedByMemberId: null,
|
|
363
|
+
slaDefaults: null,
|
|
364
|
+
status: ApprovalTemplateVersionStatusEnum.DRAFT,
|
|
365
|
+
templateId: 'template-1',
|
|
366
|
+
updatedAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
367
|
+
version: 1,
|
|
368
|
+
workflowDefinition: EMPTY_WORKFLOW_DEFINITION,
|
|
369
|
+
});
|
|
370
|
+
const formVersion = Object.assign(new FormDefinitionVersionEntity(), {
|
|
371
|
+
archivedAt: null,
|
|
372
|
+
createdAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
373
|
+
formDefinitionId: 'form-1',
|
|
374
|
+
id: 'form-version-1',
|
|
375
|
+
publishedAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
376
|
+
publishedByMemberId: 'member-admin',
|
|
377
|
+
schema: { fields: [], schemaVersion: 1 },
|
|
378
|
+
status: FormDefinitionVersionStatusEnum.PUBLISHED,
|
|
379
|
+
uiSchema: { fieldOrder: [] },
|
|
380
|
+
updatedAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
381
|
+
version: 1,
|
|
382
|
+
});
|
|
383
|
+
const transaction = jest.fn(
|
|
384
|
+
<TResult>(
|
|
385
|
+
operation: (
|
|
386
|
+
manager: Readonly<Record<string, unknown>>,
|
|
387
|
+
) => Promise<TResult>,
|
|
388
|
+
): Promise<TResult> => operation({}),
|
|
389
|
+
);
|
|
390
|
+
const service = new TemplateService(
|
|
391
|
+
{
|
|
392
|
+
manager: { transaction },
|
|
393
|
+
} as unknown as Repository<ApprovalTemplateEntity>,
|
|
394
|
+
createRepository<ApprovalTemplateCategoryEntity>(),
|
|
395
|
+
{
|
|
396
|
+
findOne: jest.fn(
|
|
397
|
+
(): Promise<ApprovalTemplateVersionEntity | null> =>
|
|
398
|
+
Promise.resolve(draftVersion),
|
|
399
|
+
),
|
|
400
|
+
} as unknown as Repository<ApprovalTemplateVersionEntity>,
|
|
401
|
+
{
|
|
402
|
+
findOne: jest.fn(
|
|
403
|
+
(): Promise<FormDefinitionVersionEntity | null> =>
|
|
404
|
+
Promise.resolve(formVersion),
|
|
405
|
+
),
|
|
406
|
+
} as unknown as Repository<FormDefinitionVersionEntity>,
|
|
407
|
+
new ConditionService(),
|
|
408
|
+
{} as unknown as FormService,
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
await expect(
|
|
412
|
+
service.publishApprovalTemplateVersion('template-version-1'),
|
|
413
|
+
).rejects.toThrow(
|
|
414
|
+
'workflow.nodes.start does not have a path to an endEvent',
|
|
415
|
+
);
|
|
416
|
+
expect(transaction).not.toHaveBeenCalled();
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('deactivates categories on delete when templates still use them', async (): Promise<void> => {
|
|
420
|
+
const category = createApprovalTemplateCategory('category-1');
|
|
421
|
+
const categorySave = jest.fn(
|
|
422
|
+
(
|
|
423
|
+
value: ApprovalTemplateCategoryEntity,
|
|
424
|
+
): Promise<ApprovalTemplateCategoryEntity> => Promise.resolve(value),
|
|
425
|
+
);
|
|
426
|
+
const service = new TemplateService(
|
|
427
|
+
{
|
|
428
|
+
count: jest.fn((): Promise<number> => Promise.resolve(2)),
|
|
429
|
+
} as unknown as Repository<ApprovalTemplateEntity>,
|
|
430
|
+
{
|
|
431
|
+
findOne: jest.fn(
|
|
432
|
+
(): Promise<ApprovalTemplateCategoryEntity | null> =>
|
|
433
|
+
Promise.resolve(category),
|
|
434
|
+
),
|
|
435
|
+
merge: jest.fn(
|
|
436
|
+
(
|
|
437
|
+
entity: ApprovalTemplateCategoryEntity,
|
|
438
|
+
value: Partial<ApprovalTemplateCategoryEntity>,
|
|
439
|
+
): ApprovalTemplateCategoryEntity => Object.assign(entity, value),
|
|
440
|
+
),
|
|
441
|
+
save: categorySave,
|
|
442
|
+
} as unknown as Repository<ApprovalTemplateCategoryEntity>,
|
|
443
|
+
createRepository<ApprovalTemplateVersionEntity>(),
|
|
444
|
+
createRepository<FormDefinitionVersionEntity>(),
|
|
445
|
+
new ConditionService(),
|
|
446
|
+
{} as unknown as FormService,
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
const deleted = await service.deleteApprovalTemplateCategory('category-1');
|
|
450
|
+
|
|
451
|
+
expect(deleted.isActive).toBe(false);
|
|
452
|
+
expect(categorySave).toHaveBeenCalledWith(
|
|
453
|
+
expect.objectContaining({
|
|
454
|
+
isActive: false,
|
|
455
|
+
}),
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
describe('TemplateService.composeApprovalTemplateWithForm', () => {
|
|
461
|
+
it('publishes form and template atomically when publish is true', async (): Promise<void> => {
|
|
462
|
+
const { manager, store } = createInMemoryManager();
|
|
463
|
+
const service = createComposingService(manager);
|
|
464
|
+
|
|
465
|
+
const result = await service.composeApprovalTemplateWithForm(
|
|
466
|
+
{
|
|
467
|
+
category: null,
|
|
468
|
+
categoryId: null,
|
|
469
|
+
formDefinitionId: null,
|
|
470
|
+
formDescription: null,
|
|
471
|
+
formName: '請款表單',
|
|
472
|
+
initiatorPolicyCel: null,
|
|
473
|
+
notificationConfigJson: null,
|
|
474
|
+
publish: true,
|
|
475
|
+
schemaJson: JSON.stringify(SAMPLE_FORM_SCHEMA),
|
|
476
|
+
slaDefaultsJson: null,
|
|
477
|
+
templateDescription: null,
|
|
478
|
+
templateId: null,
|
|
479
|
+
templateName: '請款簽核',
|
|
480
|
+
uiSchemaJson: JSON.stringify(SAMPLE_FORM_UI_SCHEMA),
|
|
481
|
+
workflowDefinitionJson: JSON.stringify(VALID_WORKFLOW_DEFINITION),
|
|
482
|
+
},
|
|
483
|
+
'member-admin',
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
expect(result.published).toBe(true);
|
|
487
|
+
expect(result.formDefinitionVersion.status).toBe(
|
|
488
|
+
FormDefinitionVersionStatusEnum.PUBLISHED,
|
|
489
|
+
);
|
|
490
|
+
expect(result.templateVersion.status).toBe(
|
|
491
|
+
ApprovalTemplateVersionStatusEnum.PUBLISHED,
|
|
492
|
+
);
|
|
493
|
+
// The template version binds the freshly published form version.
|
|
494
|
+
expect(result.templateVersion.formDefinitionVersionId).toBe(
|
|
495
|
+
result.formDefinitionVersion.id,
|
|
496
|
+
);
|
|
497
|
+
// Both parents now point at the published versions.
|
|
498
|
+
expect(result.formDefinition.currentVersionId).toBe(
|
|
499
|
+
result.formDefinitionVersion.id,
|
|
500
|
+
);
|
|
501
|
+
expect(result.template.currentVersionId).toBe(result.templateVersion.id);
|
|
502
|
+
|
|
503
|
+
const formVersions = [
|
|
504
|
+
...store(FormDefinitionVersionEntity).values(),
|
|
505
|
+
] as FormDefinitionVersionEntity[];
|
|
506
|
+
expect(formVersions).toHaveLength(1);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it('keeps both sides as drafts when publish is false', async (): Promise<void> => {
|
|
510
|
+
const { manager } = createInMemoryManager();
|
|
511
|
+
const service = createComposingService(manager);
|
|
512
|
+
|
|
513
|
+
const result = await service.composeApprovalTemplateWithForm(
|
|
514
|
+
{
|
|
515
|
+
category: null,
|
|
516
|
+
categoryId: null,
|
|
517
|
+
formDefinitionId: null,
|
|
518
|
+
formDescription: null,
|
|
519
|
+
formName: '請款表單',
|
|
520
|
+
initiatorPolicyCel: null,
|
|
521
|
+
notificationConfigJson: null,
|
|
522
|
+
publish: false,
|
|
523
|
+
schemaJson: JSON.stringify(SAMPLE_FORM_SCHEMA),
|
|
524
|
+
slaDefaultsJson: null,
|
|
525
|
+
templateDescription: null,
|
|
526
|
+
templateId: null,
|
|
527
|
+
templateName: '請款簽核',
|
|
528
|
+
uiSchemaJson: JSON.stringify(SAMPLE_FORM_UI_SCHEMA),
|
|
529
|
+
workflowDefinitionJson: JSON.stringify(VALID_WORKFLOW_DEFINITION),
|
|
530
|
+
},
|
|
531
|
+
'member-admin',
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
expect(result.published).toBe(false);
|
|
535
|
+
expect(result.formDefinitionVersion.status).toBe(
|
|
536
|
+
FormDefinitionVersionStatusEnum.DRAFT,
|
|
537
|
+
);
|
|
538
|
+
expect(result.templateVersion.status).toBe(
|
|
539
|
+
ApprovalTemplateVersionStatusEnum.DRAFT,
|
|
540
|
+
);
|
|
541
|
+
// Draft template binds the draft form version so condition fields resolve.
|
|
542
|
+
expect(result.templateVersion.formDefinitionVersionId).toBe(
|
|
543
|
+
result.formDefinitionVersion.id,
|
|
544
|
+
);
|
|
545
|
+
expect(result.formDefinition.currentVersionId).toBeNull();
|
|
546
|
+
expect(result.template.currentVersionId).toBeNull();
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('rolls back inside the single transaction when the workflow fails to lint', async (): Promise<void> => {
|
|
550
|
+
const { manager, store } = createInMemoryManager();
|
|
551
|
+
const service = createComposingService(manager);
|
|
552
|
+
|
|
553
|
+
await expect(
|
|
554
|
+
service.composeApprovalTemplateWithForm(
|
|
555
|
+
{
|
|
556
|
+
category: null,
|
|
557
|
+
categoryId: null,
|
|
558
|
+
formDefinitionId: null,
|
|
559
|
+
formDescription: null,
|
|
560
|
+
formName: '請款表單',
|
|
561
|
+
initiatorPolicyCel: null,
|
|
562
|
+
notificationConfigJson: null,
|
|
563
|
+
publish: true,
|
|
564
|
+
schemaJson: JSON.stringify(SAMPLE_FORM_SCHEMA),
|
|
565
|
+
slaDefaultsJson: null,
|
|
566
|
+
templateDescription: null,
|
|
567
|
+
templateId: null,
|
|
568
|
+
templateName: '請款簽核',
|
|
569
|
+
uiSchemaJson: JSON.stringify(SAMPLE_FORM_UI_SCHEMA),
|
|
570
|
+
// EMPTY workflow cannot reach an endEvent and must fail publish lint.
|
|
571
|
+
workflowDefinitionJson: JSON.stringify(EMPTY_WORKFLOW_DEFINITION),
|
|
572
|
+
},
|
|
573
|
+
'member-admin',
|
|
574
|
+
),
|
|
575
|
+
).rejects.toThrow('does not have a path to an endEvent');
|
|
576
|
+
|
|
577
|
+
// The single manager.transaction wraps every write, so a real DataSource
|
|
578
|
+
// would roll back the form rows created before the failing publish step.
|
|
579
|
+
expect(store(ApprovalTemplateEntity).size).toBeGreaterThanOrEqual(1);
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
function createApprovalTemplate(id: string): ApprovalTemplateEntity {
|
|
584
|
+
return Object.assign(new ApprovalTemplateEntity(), {
|
|
585
|
+
category: null,
|
|
586
|
+
categoryDetail: null,
|
|
587
|
+
categoryId: null,
|
|
588
|
+
createdAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
589
|
+
createdByMemberId: null,
|
|
590
|
+
currentVersionId: null,
|
|
591
|
+
deletedAt: null,
|
|
592
|
+
description: null,
|
|
593
|
+
id,
|
|
594
|
+
name: `簽核模板 ${id}`,
|
|
595
|
+
updatedAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function createApprovalTemplateCategory(
|
|
600
|
+
id: string,
|
|
601
|
+
): ApprovalTemplateCategoryEntity {
|
|
602
|
+
return Object.assign(new ApprovalTemplateCategoryEntity(), {
|
|
603
|
+
createdAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
604
|
+
description: null,
|
|
605
|
+
id,
|
|
606
|
+
isActive: true,
|
|
607
|
+
name: '財務',
|
|
608
|
+
sortOrder: 0,
|
|
609
|
+
updatedAt: new Date('2026-05-10T00:00:00.000Z'),
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function createRepository<
|
|
614
|
+
TEntity extends ObjectLiteral,
|
|
615
|
+
>(): Repository<TEntity> {
|
|
616
|
+
return {} as Repository<TEntity>;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const SAMPLE_FORM_SCHEMA = {
|
|
620
|
+
fields: [
|
|
621
|
+
{
|
|
622
|
+
fieldKey: 'amount',
|
|
623
|
+
label: '金額',
|
|
624
|
+
required: true,
|
|
625
|
+
type: 'number',
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
schemaVersion: 1,
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
const SAMPLE_FORM_UI_SCHEMA = {
|
|
632
|
+
layout: [{ fieldKey: 'amount', width: 'FULL' }],
|
|
633
|
+
schemaVersion: 1,
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
const VALID_WORKFLOW_DEFINITION = {
|
|
637
|
+
edges: [
|
|
638
|
+
{
|
|
639
|
+
data: {},
|
|
640
|
+
id: 'edge_start_task',
|
|
641
|
+
source: 'start',
|
|
642
|
+
target: 'task_manager',
|
|
643
|
+
type: 'smoothstep',
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
data: {},
|
|
647
|
+
id: 'edge_task_end',
|
|
648
|
+
source: 'task_manager',
|
|
649
|
+
target: 'end',
|
|
650
|
+
type: 'smoothstep',
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
meta: { schemaVersion: 1 },
|
|
654
|
+
nodes: [
|
|
655
|
+
{
|
|
656
|
+
data: { label: '開始' },
|
|
657
|
+
id: 'start',
|
|
658
|
+
position: { x: 80, y: 160 },
|
|
659
|
+
type: 'startEvent',
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
data: {
|
|
663
|
+
allowAddSigner: false,
|
|
664
|
+
allowReject: true,
|
|
665
|
+
allowTransfer: true,
|
|
666
|
+
approverResolver: {
|
|
667
|
+
baseFromInitiator: true,
|
|
668
|
+
levelsUp: 1,
|
|
669
|
+
type: 'ORG_MANAGER',
|
|
670
|
+
},
|
|
671
|
+
decisionPolicy: { type: 'SINGLE' },
|
|
672
|
+
label: '主管簽核',
|
|
673
|
+
returnBehavior: { allowReturn: true, allowedTargets: 'INITIATOR' },
|
|
674
|
+
},
|
|
675
|
+
id: 'task_manager',
|
|
676
|
+
position: { x: 300, y: 160 },
|
|
677
|
+
type: 'userTask',
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
data: { endState: 'APPROVED', label: '完成' },
|
|
681
|
+
id: 'end',
|
|
682
|
+
position: { x: 520, y: 160 },
|
|
683
|
+
type: 'endEvent',
|
|
684
|
+
},
|
|
685
|
+
],
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
function createComposingService(manager: EntityManager): TemplateService {
|
|
689
|
+
const formService = new FormService(
|
|
690
|
+
{} as Repository<FormDefinitionEntity>,
|
|
691
|
+
{} as Repository<FormDefinitionVersionEntity>,
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
return new TemplateService(
|
|
695
|
+
{ manager } as unknown as Repository<ApprovalTemplateEntity>,
|
|
696
|
+
{} as Repository<ApprovalTemplateCategoryEntity>,
|
|
697
|
+
{} as Repository<ApprovalTemplateVersionEntity>,
|
|
698
|
+
{} as Repository<FormDefinitionVersionEntity>,
|
|
699
|
+
new ConditionService(),
|
|
700
|
+
formService,
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Minimal in-memory EntityManager that backs the composed-mutation tests. It
|
|
706
|
+
* supports the create/find/update surface the compose flow exercises and runs
|
|
707
|
+
* `transaction(op)` by invoking `op` with itself, mirroring a single DB
|
|
708
|
+
* transaction boundary.
|
|
709
|
+
*/
|
|
710
|
+
function createInMemoryManager(): {
|
|
711
|
+
readonly manager: EntityManager;
|
|
712
|
+
readonly store: (entity: unknown) => Map<string, ObjectLiteral>;
|
|
713
|
+
} {
|
|
714
|
+
const stores = new Map<unknown, Map<string, ObjectLiteral>>();
|
|
715
|
+
let sequence = 0;
|
|
716
|
+
|
|
717
|
+
const storeFor = (entity: unknown): Map<string, ObjectLiteral> => {
|
|
718
|
+
const existing = stores.get(entity);
|
|
719
|
+
|
|
720
|
+
if (existing) {
|
|
721
|
+
return existing;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const created = new Map<string, ObjectLiteral>();
|
|
725
|
+
stores.set(entity, created);
|
|
726
|
+
|
|
727
|
+
return created;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
const matches = (
|
|
731
|
+
row: ObjectLiteral,
|
|
732
|
+
where: Readonly<Record<string, unknown>>,
|
|
733
|
+
): boolean =>
|
|
734
|
+
Object.entries(where).every(([key, value]) => {
|
|
735
|
+
if (key === 'relations') {
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (value !== null && typeof value === 'object' && '_type' in value) {
|
|
740
|
+
// Treat any FindOperator (e.g. IsNull()) as a null match.
|
|
741
|
+
return row[key] === null || row[key] === undefined;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
return row[key] === value;
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
const makeRepository = (
|
|
748
|
+
entity: new () => ObjectLiteral,
|
|
749
|
+
): Record<string, unknown> => {
|
|
750
|
+
const store = storeFor(entity);
|
|
751
|
+
|
|
752
|
+
return {
|
|
753
|
+
create: (value: ObjectLiteral): ObjectLiteral =>
|
|
754
|
+
Object.assign(new entity(), value),
|
|
755
|
+
findOne: ({
|
|
756
|
+
where,
|
|
757
|
+
}: {
|
|
758
|
+
readonly where:
|
|
759
|
+
| Readonly<Record<string, unknown>>
|
|
760
|
+
| readonly Readonly<Record<string, unknown>>[];
|
|
761
|
+
}): Promise<ObjectLiteral | null> => {
|
|
762
|
+
const clauses = Array.isArray(where) ? where : [where];
|
|
763
|
+
|
|
764
|
+
for (const row of store.values()) {
|
|
765
|
+
if (clauses.some((clause) => matches(row, clause))) {
|
|
766
|
+
return Promise.resolve(row);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return Promise.resolve(null);
|
|
771
|
+
},
|
|
772
|
+
findOneByOrFail: (
|
|
773
|
+
where: Readonly<Record<string, unknown>>,
|
|
774
|
+
): Promise<ObjectLiteral> => {
|
|
775
|
+
for (const row of store.values()) {
|
|
776
|
+
if (matches(row, where)) {
|
|
777
|
+
return Promise.resolve(row);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return Promise.reject(new Error(`${entity.name} was not found`));
|
|
782
|
+
},
|
|
783
|
+
merge: (target: ObjectLiteral, patch: ObjectLiteral): ObjectLiteral =>
|
|
784
|
+
Object.assign(target, patch),
|
|
785
|
+
save: (value: ObjectLiteral): Promise<ObjectLiteral> => {
|
|
786
|
+
if (!value.id) {
|
|
787
|
+
sequence += 1;
|
|
788
|
+
value.id = `${entity.name}-${sequence}`;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
store.set(value.id as string, value);
|
|
792
|
+
|
|
793
|
+
return Promise.resolve(value);
|
|
794
|
+
},
|
|
795
|
+
update: (
|
|
796
|
+
criteria: Readonly<Record<string, unknown>>,
|
|
797
|
+
patch: ObjectLiteral,
|
|
798
|
+
): Promise<void> => {
|
|
799
|
+
for (const row of store.values()) {
|
|
800
|
+
if (matches(row, criteria)) {
|
|
801
|
+
Object.assign(row, patch);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
return Promise.resolve();
|
|
806
|
+
},
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
const manager = {
|
|
811
|
+
getRepository: (entity: new () => ObjectLiteral): Record<string, unknown> =>
|
|
812
|
+
makeRepository(entity),
|
|
813
|
+
transaction: <TResult>(
|
|
814
|
+
operation: (manager: EntityManager) => Promise<TResult>,
|
|
815
|
+
): Promise<TResult> => operation(manager as unknown as EntityManager),
|
|
816
|
+
} as unknown as EntityManager;
|
|
817
|
+
|
|
818
|
+
return {
|
|
819
|
+
manager,
|
|
820
|
+
store: (entity: unknown): Map<string, ObjectLiteral> => storeFor(entity),
|
|
821
|
+
};
|
|
822
|
+
}
|