@futdevpro/nts-dynamo 1.15.151 → 1.15.154
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/.c8rc.json +26 -26
- package/.copilot/patterns.json +7 -7
- package/.cursor/rules/__assistant_guide.mdc +30 -30
- package/.cursor/rules/__main.mdc +64 -64
- package/.cursor/rules/_ag_backend-structure.mdc +85 -85
- package/.cursor/rules/_ag_backend.mdc +16 -16
- package/.cursor/rules/_ag_debug.mdc +7 -7
- package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -372
- package/.cursor/rules/_ag_file-refactoring.mdc +113 -113
- package/.cursor/rules/_ag_fixes_rules.mdc +5 -5
- package/.cursor/rules/_ag_frontend-structure.mdc +86 -86
- package/.cursor/rules/_ag_frontend.mdc +39 -39
- package/.cursor/rules/_ag_import-rules.mdc +44 -44
- package/.cursor/rules/_ag_naming.mdc +115 -115
- package/.cursor/rules/_ag_running_commands.mdc +4 -4
- package/.cursor/rules/_ag_server-controller.mdc +5 -5
- package/.cursor/rules/_ag_should-be.mdc +6 -6
- package/.cursor/rules/_ag_swearing.mdc +47 -47
- package/.cursor/rules/ai_development_guide.md +60 -60
- package/.cursor/rules/ai_directives.md +114 -114
- package/.cursor/rules/cursor-rules.md +160 -160
- package/.cursor/rules/default-command.mdc +464 -464
- package/.cursor/rules/error_code_pattern.md +39 -39
- package/.cursor/rules/saved rule mcp server use.md +15 -15
- package/.dynamo/pipeline.cicd.config.json +190 -190
- package/.dynamo/version-bump.config.json +5 -5
- package/.github/workflows/main.yml +438 -438
- package/.husky/pre-commit +3 -3
- package/.vscode/settings.json +10 -10
- package/HOWTO.md +15 -15
- package/LICENSE +21 -21
- package/README.md +790 -749
- package/__documentations/2026-04-28-logs-module.md +49 -49
- package/__documentations/2026-05-17-oai-compatible-providers.md +229 -229
- package/__documentations/2026-05-17-static-client-serving-howto.md +144 -144
- package/__documentations/2026-06-01-fr041-cors-middleware.md +96 -96
- package/__documentations/2026-06-01-fr047-p2p3-function-calling.md +81 -81
- package/__documentations/2026-06-15-fr193-memory-guard.md +73 -73
- package/__documentations/2026-08-08-fr292-app-version-header.md +38 -38
- package/__documentations/2026-08-14-field-encryption-mongoose-document-spread.md +124 -124
- package/__documentations/2026-08-18-artifact-compiler.md +46 -46
- package/__documentations/2026-08-18-mongo-transaction-control-service.md +82 -82
- package/__documentations/2026-08-18-standalone-account-security-and-privacy-bedrock.md +132 -132
- package/__documentations/2026-08-21-distributed-rate-limit-bfr-ctm-010.md +59 -59
- package/__documentations/2026-08-22-content-free-process-error-boundary.md +91 -0
- package/__documentations/2026-08-22-npm-token-state-classifier.md +92 -92
- package/__documentations/nts-integration-tests-2026-03-17.md +26 -26
- package/__documentations/plans/BEDROCK-HYPERPLAN.md +95 -95
- package/_specifications/BACKLOG.md +92 -92
- package/_specifications/TODO.md +15 -15
- package/_specifications/agent.md +138 -138
- package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +1 -2
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_modules/server/index.d.ts +8 -0
- package/build/_modules/server/index.d.ts.map +1 -1
- package/build/_modules/server/index.js +9 -0
- package/build/_modules/server/index.js.map +1 -1
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.d.ts +9 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.d.ts.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.js +13 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.js.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.d.ts +20 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.d.ts.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.js +24 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.js.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.control-service.d.ts +19 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.control-service.d.ts.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.control-service.js +83 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.control-service.js.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.interface.d.ts +19 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.interface.d.ts.map +1 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.interface.js +3 -0
- package/build/_modules/server/safe-diagnostic/safe-diagnostic.interface.js.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe-code.type-enum.d.ts +14 -0
- package/build/_modules/server/server-status/db-readiness-probe-code.type-enum.d.ts.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe-code.type-enum.js +18 -0
- package/build/_modules/server/server-status/db-readiness-probe-code.type-enum.js.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe-stage.type-enum.d.ts +8 -0
- package/build/_modules/server/server-status/db-readiness-probe-stage.type-enum.d.ts.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe-stage.type-enum.js +12 -0
- package/build/_modules/server/server-status/db-readiness-probe-stage.type-enum.js.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe.control-service.d.ts +14 -0
- package/build/_modules/server/server-status/db-readiness-probe.control-service.d.ts.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe.control-service.js +126 -0
- package/build/_modules/server/server-status/db-readiness-probe.control-service.js.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe.interface.d.ts +18 -0
- package/build/_modules/server/server-status/db-readiness-probe.interface.d.ts.map +1 -0
- package/build/_modules/server/server-status/db-readiness-probe.interface.js +3 -0
- package/build/_modules/server/server-status/db-readiness-probe.interface.js.map +1 -0
- package/build/_services/core/global.service.d.ts +3 -3
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +24 -18
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts +2 -0
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +71 -199
- package/build/_services/server/app.server.js.map +1 -1
- package/eslint.config.js +3 -3
- package/nodemon.json +24 -24
- package/package.json +1 -1
- package/pnpm-workspace.yaml +6 -6
- package/scripts/_seed-out/aim-seed.fixtures.ts +161 -161
- package/scripts/_seed-out/llm-expand-raw.json +59 -59
- package/scripts/_seed-out/seed-raw.json +152 -152
- package/scripts/ai-fixture-seed.js +126 -126
- package/scripts/run-coverage-tests.js +28 -28
- package/spec/support/helpers/spec-reporter-loader.js +359 -359
- package/spec/support/helpers/ts-node-helper.js +93 -93
- package/spec/support/jasmine.coverage.json +24 -24
- package/spec/support/jasmine.json +24 -24
- package/src/_collections/app-version-header.util.spec.ts +108 -108
- package/src/_collections/app-version-header.util.ts +74 -74
- package/src/_collections/archive-service-registry.const.ts +21 -21
- package/src/_collections/archive.util.spec.ts +57 -57
- package/src/_collections/archive.util.ts +18 -18
- package/src/_collections/atlas-default-db-options.const.ts +9 -9
- package/src/_collections/client-safe-error.util.spec.ts +151 -151
- package/src/_collections/client-safe-error.util.ts +107 -107
- package/src/_collections/default-fallback-cache-max-age.const.spec.ts +11 -11
- package/src/_collections/default-fallback-cache-max-age.const.ts +2 -2
- package/src/_collections/default-not-found-page.const.spec.ts +19 -19
- package/src/_collections/default-not-found-page.const.ts +22 -22
- package/src/_collections/default-socket-path.const.spec.ts +12 -12
- package/src/_collections/default-socket-path.const.ts +2 -2
- package/src/_collections/field-encryption.util.spec.ts +195 -195
- package/src/_collections/field-encryption.util.ts +222 -222
- package/src/_collections/get-environment-settings.util.spec.ts +210 -210
- package/src/_collections/get-environment-settings.util.ts +48 -48
- package/src/_collections/global-settings.const.ts +126 -126
- package/src/_collections/load-shed.util.spec.ts +62 -62
- package/src/_collections/load-shed.util.ts +51 -51
- package/src/_collections/mongo-reconnect-guard.util.spec.ts +52 -52
- package/src/_collections/mongo-reconnect-guard.util.ts +172 -172
- package/src/_collections/npm-token-check.util.spec.ts +218 -218
- package/src/_collections/npm-token-check.util.ts +327 -327
- package/src/_collections/sample.env +21 -21
- package/src/_collections/security-headers.util.spec.ts +98 -98
- package/src/_collections/security-headers.util.ts +96 -96
- package/src/_collections/signed-url.util.spec.ts +198 -198
- package/src/_collections/signed-url.util.ts +170 -170
- package/src/_collections/star.controller.spec.ts +224 -224
- package/src/_collections/star.controller.ts +129 -129
- package/src/_collections/static-cache-control.util.spec.ts +47 -47
- package/src/_collections/static-cache-control.util.ts +25 -25
- package/src/_enums/data-model-type.enum.ts +14 -14
- package/src/_enums/data-service-function.enum.ts +24 -24
- package/src/_enums/predefined-data-types.enum.ts +16 -16
- package/src/_enums/route-security.enum.ts +12 -12
- package/src/_models/control-models/api-call-params.control-model.spec.ts +152 -152
- package/src/_models/control-models/api-call-params.control-model.ts +142 -142
- package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -52
- package/src/_models/control-models/app-ext-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/app-params.control-model.spec.ts +213 -209
- package/src/_models/control-models/app-params.control-model.ts +130 -129
- package/src/_models/control-models/app-system-controls.control-model.spec.ts +31 -31
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/endpoint-params.control-model.spec.ts +669 -669
- package/src/_models/control-models/endpoint-params.control-model.ts +664 -664
- package/src/_models/control-models/http-settings.control-model.spec.ts +77 -77
- package/src/_models/control-models/http-settings.control-model.ts +37 -37
- package/src/_models/control-models/system-control.control-model.spec.ts +27 -27
- package/src/_models/control-models/system-control.control-model.ts +12 -12
- package/src/_models/data-models/schema-migration.data-model.ts +50 -50
- package/src/_models/interfaces/app-version-header-settings.interface.ts +17 -17
- package/src/_models/interfaces/certification-settings.interface.ts +7 -7
- package/src/_models/interfaces/compare-data-options.interface.ts +27 -27
- package/src/_models/interfaces/compare-data-result.interface.ts +12 -12
- package/src/_models/interfaces/cors-settings.interface.spec.ts +52 -52
- package/src/_models/interfaces/cors-settings.interface.ts +56 -56
- package/src/_models/interfaces/db-query-options.interface.ts +33 -33
- package/src/_models/interfaces/environment-settings.interface.ts +59 -59
- package/src/_models/interfaces/global-log-settings.interface.ts +171 -171
- package/src/_models/interfaces/global-service-settings.interface.ts +47 -47
- package/src/_models/interfaces/global-settings.interface.ts +294 -294
- package/src/_models/interfaces/migration-entry.interface.ts +19 -19
- package/src/_models/interfaces/mongo-transaction-settings.interface.ts +9 -9
- package/src/_models/interfaces/routing-module-settings.interface.ts +21 -21
- package/src/_models/interfaces/security-headers-settings.interface.ts +50 -50
- package/src/_models/interfaces/signed-url-verify-result.interface.ts +13 -13
- package/src/_models/interfaces/static-client-settings.interface.spec.ts +29 -29
- package/src/_models/interfaces/static-client-settings.interface.ts +36 -36
- package/src/_models/types/db-update.type.ts +100 -100
- package/src/_modules/account-security/_enums/account-challenge-purpose.type-enum.ts +5 -5
- package/src/_modules/account-security/_enums/account-refresh-token-state.type-enum.ts +6 -6
- package/src/_modules/account-security/_enums/account-session-state.type-enum.ts +6 -6
- package/src/_modules/account-security/_models/account-challenge-adapter.interface.ts +17 -17
- package/src/_modules/account-security/_models/account-challenge-issued.interface.ts +6 -6
- package/src/_modules/account-security/_models/account-challenge-record.interface.ts +13 -13
- package/src/_modules/account-security/_models/account-challenge-result.interface.ts +8 -8
- package/src/_modules/account-security/_models/account-challenge-settings.interface.ts +9 -9
- package/src/_modules/account-security/_models/account-password-policy.interface.ts +11 -11
- package/src/_modules/account-security/_models/account-password-verification.interface.ts +5 -5
- package/src/_modules/account-security/_models/account-refresh-token-record.interface.ts +13 -13
- package/src/_modules/account-security/_models/account-session-adapter.interface.ts +19 -19
- package/src/_modules/account-security/_models/account-session-claims.interface.ts +7 -7
- package/src/_modules/account-security/_models/account-session-context.interface.ts +6 -6
- package/src/_modules/account-security/_models/account-session-create.interface.ts +8 -8
- package/src/_modules/account-security/_models/account-session-record.interface.ts +21 -21
- package/src/_modules/account-security/_models/account-session-rotate.interface.ts +11 -11
- package/src/_modules/account-security/_models/account-session-settings.interface.ts +11 -11
- package/src/_modules/account-security/_models/account-session-token-pair.interface.ts +8 -8
- package/src/_modules/account-security/_models/account-session-view.interface.ts +13 -13
- package/src/_modules/account-security/account-challenge.control-service.spec.ts +195 -195
- package/src/_modules/account-security/account-challenge.control-service.ts +164 -164
- package/src/_modules/account-security/account-password.control-service.spec.ts +96 -96
- package/src/_modules/account-security/account-password.control-service.ts +288 -288
- package/src/_modules/account-security/account-session.control-service.spec.ts +294 -294
- package/src/_modules/account-security/account-session.control-service.ts +376 -376
- package/src/_modules/account-security/index.ts +31 -31
- package/src/_modules/admin-auth/_models/admin-api-key-config.interface.ts +33 -33
- package/src/_modules/admin-auth/admin-api-key.auth-service.spec.ts +200 -200
- package/src/_modules/admin-auth/admin-api-key.auth-service.ts +220 -220
- package/src/_modules/admin-auth/index.ts +2 -2
- package/src/_modules/ai/_collections/ai-model-config-validator.util.spec.ts +150 -150
- package/src/_modules/ai/_collections/ai-model-config-validator.util.ts +131 -131
- package/src/_modules/ai/_collections/ai-provider-error.util.ts +144 -144
- package/src/_modules/ai/_models/ai-input-interfaces.ts +117 -117
- package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -16
- package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event-callback.interface.ts +14 -14
- package/src/_modules/ai/_models/interfaces/dynts-ai-cost-event.interface.ts +56 -56
- package/src/_modules/ai/_models/interfaces/dynts-ai-provider-error.interface.ts +16 -16
- package/src/_modules/ai/_modules/ai-mock/_collections/aim-default-collection.util.spec.ts +72 -72
- package/src/_modules/ai/_modules/ai-mock/_collections/aim-default-collection.util.ts +71 -71
- package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-match.util.spec.ts +57 -57
- package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-match.util.ts +60 -60
- package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-serializer.util.spec.ts +56 -56
- package/src/_modules/ai/_modules/ai-mock/_collections/aim-fixture-serializer.util.ts +117 -117
- package/src/_modules/ai/_modules/ai-mock/_enums/aim-modality.enum.ts +28 -28
- package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-call-input.interface.ts +14 -14
- package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-error.interface.ts +11 -11
- package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-fixture.interface.ts +30 -30
- package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-request.interface.ts +19 -19
- package/src/_modules/ai/_modules/ai-mock/_models/interfaces/aim-service-collection.interface.ts +20 -20
- package/src/_modules/ai/_modules/ai-mock/_services/ai-embedding-mock.service.spec.ts +115 -115
- package/src/_modules/ai/_modules/ai-mock/_services/ai-embedding-mock.service.ts +233 -233
- package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-harness.service.spec.ts +134 -134
- package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-harness.service.ts +127 -127
- package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-pipeline.spec.ts +105 -105
- package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-store.service.spec.ts +50 -50
- package/src/_modules/ai/_modules/ai-mock/_services/aim-fixture-store.service.ts +65 -65
- package/src/_modules/ai/_modules/ai-mock/_services/aim-integration-proof.spec.ts +92 -92
- package/src/_modules/ai/_modules/ai-mock/_services/aim-mock.service.spec.ts +112 -112
- package/src/_modules/ai/_modules/ai-mock/_services/aim-mock.service.ts +155 -155
- package/src/_modules/ai/_modules/ai-mock/fixtures/aim-text.fixtures.ts +649 -649
- package/src/_modules/ai/_modules/ai-mock/index.ts +47 -47
- package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -138
- package/src/_modules/ai/_modules/anthropic/index.ts +5 -5
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -242
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.ts +639 -639
- package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.spec.ts +295 -295
- package/src/_modules/ai/_modules/document-ai/_collections/dai-code-chunking.util.ts +552 -552
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -209
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.ts +85 -85
- package/src/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.ts +7 -7
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +146 -146
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +162 -162
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.ts +99 -99
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-code-chunk.interface.ts +68 -68
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.ts +18 -18
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.ts +19 -19
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.ts +25 -25
- package/src/_modules/ai/_modules/document-ai/index.ts +30 -30
- package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -189
- package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -5
- package/src/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -9
- package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +82 -82
- package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +75 -75
- package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -45
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +7 -7
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -7
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -57
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.ts +292 -292
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.ts +572 -572
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -342
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.ts +435 -435
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -550
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.ts +630 -630
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +332 -332
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +132 -132
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -462
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +634 -634
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +489 -489
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.tools.spec.ts +173 -173
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +1085 -1085
- package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -157
- package/src/_modules/ai/_modules/open-ai/index.ts +74 -74
- package/src/_modules/ai/_services/ai-embedding-provider.registry.spec.ts +110 -110
- package/src/_modules/ai/_services/ai-embedding-provider.registry.ts +114 -114
- package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -98
- package/src/_modules/ai/_services/ai-embedding.service-base.ts +48 -48
- package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -229
- package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +68 -68
- package/src/_modules/ai/_services/ai-llm.service-base.reconciler.spec.ts +133 -133
- package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -250
- package/src/_modules/ai/_services/ai-llm.service-base.ts +599 -599
- package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +158 -158
- package/src/_modules/ai/_services/ai-provider.service-base.ts +67 -67
- package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -59
- package/src/_modules/ai/_services/lmstudio-embedding.control-service.spec.ts +197 -197
- package/src/_modules/ai/_services/lmstudio-embedding.control-service.ts +399 -399
- package/src/_modules/ai/index.ts +33 -33
- package/src/_modules/artifact-compiler/_enums/artifact-compile-outcome.type-enum.ts +5 -5
- package/src/_modules/artifact-compiler/_enums/artifact-compile-stage.type-enum.ts +8 -8
- package/src/_modules/artifact-compiler/_enums/artifact-retry-class.type-enum.ts +6 -6
- package/src/_modules/artifact-compiler/_models/artifact-compile.interface.ts +35 -35
- package/src/_modules/artifact-compiler/artifact-compiler.control-service.spec.ts +151 -151
- package/src/_modules/artifact-compiler/artifact-compiler.control-service.ts +356 -356
- package/src/_modules/artifact-compiler/index.ts +9 -9
- package/src/_modules/assistant/_collections/ass-global-settings.const.ts +13 -13
- package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -176
- package/src/_modules/assistant/_collections/ass.util.ts +50 -50
- package/src/_modules/assistant/_models/ass-global-settings.interface.ts +15 -15
- package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -140
- package/src/_modules/assistant/_services/ass-io.control-service.ts +74 -74
- package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -192
- package/src/_modules/assistant/_services/ass-main.control-service.ts +107 -107
- package/src/_modules/assistant/index.ts +19 -19
- package/src/_modules/bot/_collections/bot-default-commands.const.ts +12 -12
- package/src/_modules/bot/_collections/bot-global-settings.const.ts +39 -39
- package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +62 -62
- package/src/_modules/bot/_models/bot-command.interface.ts +8 -8
- package/src/_modules/bot/_models/bot-global-settings.interface.ts +96 -96
- package/src/_modules/bot/_models/bot-last-mention-date.interface.ts +6 -6
- package/src/_modules/bot/_models/bot-last-message-date.interface.ts +5 -5
- package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +90 -90
- package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +41 -41
- package/src/_modules/bot/_modules/discord-bot/_models/dib-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -431
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.ts +641 -641
- package/src/_modules/bot/_modules/discord-bot/index.ts +12 -12
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -160
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +55 -55
- package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +15 -15
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -374
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +447 -447
- package/src/_modules/bot/_modules/dynamo-bot/index.ts +15 -15
- package/src/_modules/bot/_modules/slack-bot/_models/slb-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -344
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.ts +197 -197
- package/src/_modules/bot/_modules/slack-bot/index.ts +12 -12
- package/src/_modules/bot/_modules/teams-bot/_models/teb-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -345
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.ts +197 -197
- package/src/_modules/bot/_modules/teams-bot/index.ts +11 -11
- package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -116
- package/src/_modules/bot/_services/bot-commands.control-service.ts +158 -158
- package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -285
- package/src/_modules/bot/_services/bot-io.control-service.ts +329 -329
- package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -208
- package/src/_modules/bot/_services/bot-main.control-service.ts +489 -489
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -349
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.ts +158 -158
- package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -111
- package/src/_modules/bot/_services/bot-routines.control-service.ts +78 -78
- package/src/_modules/bot/index.ts +37 -37
- package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -49
- package/src/_modules/custom-data/custom-data.controller.ts +67 -67
- package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -54
- package/src/_modules/custom-data/custom-data.data-service.ts +21 -21
- package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -28
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +24 -24
- package/src/_modules/custom-data/index.ts +9 -9
- package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.spec.ts +176 -176
- package/src/_modules/data-readers/_collections/dynts-sqlite-reader.util.ts +203 -203
- package/src/_modules/data-readers/_models/interfaces/dynts-sqlite-reader.interface.ts +33 -33
- package/src/_modules/data-readers/index.ts +11 -11
- package/src/_modules/defaults/_collections/default-endpoints.util.ts +487 -487
- package/src/_modules/defaults/_models/default-user.data-model.ts +72 -72
- package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -269
- package/src/_modules/defaults/_services/default-auth.service.ts +177 -177
- package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -42
- package/src/_modules/defaults/_services/default-socket-events.service.ts +61 -61
- package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -187
- package/src/_modules/defaults/_services/default-user.data-service.ts +98 -98
- package/src/_modules/defaults/index.ts +17 -17
- package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -19
- package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -366
- package/src/_modules/discord-assistant/_collections/dias.util.ts +132 -132
- package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +19 -19
- package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +52 -52
- package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +177 -177
- package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -108
- package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +69 -69
- package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -22
- package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +27 -27
- package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -195
- package/src/_modules/discord-assistant/_services/dias.service-base.ts +76 -76
- package/src/_modules/discord-assistant/index.ts +38 -38
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -34
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -11
- package/src/_modules/discord-assistant-voiced/index.ts +36 -36
- package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +16 -16
- package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +55 -55
- package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -214
- package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +387 -387
- package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -12
- package/src/_modules/discord-bot/_models/dibo-global-settings.interface.ts +98 -98
- package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +7 -7
- package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -6
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -154
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +153 -153
- package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -264
- package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +306 -306
- package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -408
- package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +487 -487
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -105
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +97 -97
- package/src/_modules/discord-bot/index.ts +36 -36
- package/src/_modules/local-vector-search/_enums/lvs-search-mode.enum.ts +35 -35
- package/src/_modules/local-vector-search/_models/data-models/lvs-vector-persist.data-model.ts +60 -60
- package/src/_modules/local-vector-search/_models/lvs-search-result.interface.ts +17 -17
- package/src/_modules/local-vector-search/_services/lvs-bm25.util.spec.ts +159 -159
- package/src/_modules/local-vector-search/_services/lvs-bm25.util.ts +206 -206
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -418
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.ts +276 -276
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +480 -480
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.ts +416 -416
- package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.spec.ts +214 -214
- package/src/_modules/local-vector-search/_services/lvs-persistent-vector-pool.control-service.ts +186 -186
- package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.spec.ts +167 -167
- package/src/_modules/local-vector-search/_services/lvs-vector-persist.data-service.ts +130 -130
- package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.ts +509 -509
- package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.ts +323 -323
- package/src/_modules/local-vector-search/index.ts +16 -16
- package/src/_modules/logs/_models/file-log-entry.interface.ts +13 -13
- package/src/_modules/logs/_models/file-log-read-result.interface.ts +37 -37
- package/src/_modules/logs/file-log.service.spec.ts +341 -341
- package/src/_modules/logs/file-log.service.ts +466 -466
- package/src/_modules/logs/file-logs.controller.spec.ts +245 -245
- package/src/_modules/logs/file-logs.controller.ts +165 -165
- package/src/_modules/logs/get-file-logs-routing-module.util.ts +51 -51
- package/src/_modules/logs/get-logs-routing-module.util.ts +36 -36
- package/src/_modules/logs/index.ts +11 -11
- package/src/_modules/logs/log-buffer.service.ts +101 -101
- package/src/_modules/logs/logs.controller.ts +109 -109
- package/src/_modules/logs/logs.service.ts +100 -100
- package/src/_modules/mcp/_models/interfaces/dynts-mcp.interface.ts +111 -111
- package/src/_modules/mcp/_services/dynts-mcp-server.service-base.spec.ts +151 -151
- package/src/_modules/mcp/_services/dynts-mcp-server.service-base.ts +125 -125
- package/src/_modules/mcp/_services/dynts-mcp.adapter.ts +168 -168
- package/src/_modules/mcp/index.ts +13 -13
- package/src/_modules/messaging/README.md +354 -354
- package/src/_modules/messaging/_collections/get-messaging-routing-module.util.ts +26 -26
- package/src/_modules/messaging/_collections/msg-global-settings.const.ts +22 -22
- package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -226
- package/src/_modules/messaging/_collections/msg.util.ts +83 -83
- package/src/_modules/messaging/_models/msg-global-settings.interface.ts +37 -37
- package/src/_modules/messaging/_services/msg-conversation.data-service.ts +146 -146
- package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -219
- package/src/_modules/messaging/_services/msg-events.service.ts +267 -267
- package/src/_modules/messaging/_services/msg-integration.control-service.ts +179 -179
- package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -147
- package/src/_modules/messaging/_services/msg-main.control-service.ts +571 -571
- package/src/_modules/messaging/_services/msg-message.data-service.ts +129 -129
- package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -201
- package/src/_modules/messaging/_services/msg.controller.ts +370 -370
- package/src/_modules/messaging/index.ts +30 -30
- package/src/_modules/mock/app-extended-server.mock.ts +201 -201
- package/src/_modules/mock/app-integration-test.mock.ts +51 -51
- package/src/_modules/mock/app-params.mock.spec.ts +21 -21
- package/src/_modules/mock/app-params.mock.ts +9 -9
- package/src/_modules/mock/app-server.mock.ts +188 -188
- package/src/_modules/mock/auth-service.mock.spec.ts +47 -47
- package/src/_modules/mock/auth-service.mock.ts +28 -28
- package/src/_modules/mock/controller.mock.spec.ts +26 -26
- package/src/_modules/mock/controller.mock.ts +16 -16
- package/src/_modules/mock/data-model.mock.spec.ts +111 -111
- package/src/_modules/mock/data-model.mock.ts +82 -82
- package/src/_modules/mock/email-service-collection.mock.spec.ts +24 -24
- package/src/_modules/mock/email-service-collection.mock.ts +15 -15
- package/src/_modules/mock/email-service.mock.spec.ts +17 -17
- package/src/_modules/mock/email-service.mock.ts +20 -20
- package/src/_modules/mock/email-template.mock.html +14 -14
- package/src/_modules/mock/endpoint.mock.ts +91 -91
- package/src/_modules/mock/socket-client.mock.spec.ts +40 -40
- package/src/_modules/mock/socket-client.mock.ts +45 -45
- package/src/_modules/mock/socket-server.mock.spec.ts +44 -44
- package/src/_modules/mock/socket-server.mock.ts +46 -46
- package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -107
- package/src/_modules/oauth2/_routes/oauth2.controller.ts +98 -98
- package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -254
- package/src/_modules/oauth2/_services/oauth2.auth-service.ts +232 -232
- package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -585
- package/src/_modules/oauth2/_services/oauth2.control-service.ts +653 -653
- package/src/_modules/oauth2/index.ts +17 -17
- package/src/_modules/privacy-lifecycle/_enums/privacy-consent-decision.type-enum.ts +5 -5
- package/src/_modules/privacy-lifecycle/_enums/privacy-contributor-action.type-enum.ts +10 -10
- package/src/_modules/privacy-lifecycle/_enums/privacy-contributor-outcome.type-enum.ts +7 -7
- package/src/_modules/privacy-lifecycle/_enums/privacy-request-state.type-enum.ts +15 -15
- package/src/_modules/privacy-lifecycle/_enums/privacy-request.type-enum.ts +9 -9
- package/src/_modules/privacy-lifecycle/_models/privacy-consent-input.interface.ts +12 -12
- package/src/_modules/privacy-lifecycle/_models/privacy-consent-persistence-result.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-consent-record.interface.ts +15 -15
- package/src/_modules/privacy-lifecycle/_models/privacy-consent-result.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-consent-view.interface.ts +13 -13
- package/src/_modules/privacy-lifecycle/_models/privacy-contributor-context.interface.ts +9 -9
- package/src/_modules/privacy-lifecycle/_models/privacy-contributor-outcome.interface.ts +14 -14
- package/src/_modules/privacy-lifecycle/_models/privacy-contributor-plan.interface.ts +8 -8
- package/src/_modules/privacy-lifecycle/_models/privacy-contributor.interface.ts +17 -17
- package/src/_modules/privacy-lifecycle/_models/privacy-ledger-adapter.interface.ts +21 -21
- package/src/_modules/privacy-lifecycle/_models/privacy-ledger-result.interface.ts +9 -9
- package/src/_modules/privacy-lifecycle/_models/privacy-ledger-settings.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-input.interface.ts +10 -10
- package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-persistence-result.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-result.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance-view.interface.ts +11 -11
- package/src/_modules/privacy-lifecycle/_models/privacy-legal-acceptance.interface.ts +13 -13
- package/src/_modules/privacy-lifecycle/_models/privacy-lifecycle-adapter.interface.ts +19 -19
- package/src/_modules/privacy-lifecycle/_models/privacy-lifecycle-settings.interface.ts +9 -9
- package/src/_modules/privacy-lifecycle/_models/privacy-request-create-result.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-request-open.interface.ts +10 -10
- package/src/_modules/privacy-lifecycle/_models/privacy-request-persistence-create-result.interface.ts +7 -7
- package/src/_modules/privacy-lifecycle/_models/privacy-request-record.interface.ts +21 -21
- package/src/_modules/privacy-lifecycle/_models/privacy-request-result.interface.ts +8 -8
- package/src/_modules/privacy-lifecycle/_models/privacy-request-view.interface.ts +20 -20
- package/src/_modules/privacy-lifecycle/index.ts +40 -40
- package/src/_modules/privacy-lifecycle/privacy-ledger.control-service.spec.ts +206 -206
- package/src/_modules/privacy-lifecycle/privacy-ledger.control-service.ts +253 -253
- package/src/_modules/privacy-lifecycle/privacy-lifecycle.control-service.spec.ts +353 -353
- package/src/_modules/privacy-lifecycle/privacy-lifecycle.control-service.ts +586 -586
- package/src/_modules/rate-limit/_enums/rate-limit-store-kind.type-enum.ts +5 -5
- package/src/_modules/rate-limit/_models/rate-limit-config.interface.ts +82 -82
- package/src/_modules/rate-limit/_models/rate-limit-consume-request.interface.ts +9 -9
- package/src/_modules/rate-limit/_models/rate-limit-consume-result.interface.ts +6 -6
- package/src/_modules/rate-limit/_models/rate-limit-policy.interface.ts +16 -16
- package/src/_modules/rate-limit/_models/rate-limit-store.interface.ts +9 -9
- package/src/_modules/rate-limit/index.ts +8 -8
- package/src/_modules/rate-limit/rate-limit-in-memory.store.ts +91 -91
- package/src/_modules/rate-limit/rate-limit.middleware.spec.ts +488 -488
- package/src/_modules/rate-limit/rate-limit.middleware.ts +504 -504
- package/src/_modules/scheduler/_models/scheduler-job.interface.ts +35 -35
- package/src/_modules/scheduler/get-scheduler-routing-module.util.ts +33 -33
- package/src/_modules/scheduler/index.ts +8 -8
- package/src/_modules/scheduler/scheduler.controller.spec.ts +42 -42
- package/src/_modules/scheduler/scheduler.controller.ts +69 -69
- package/src/_modules/scheduler/scheduler.service.spec.ts +141 -141
- package/src/_modules/scheduler/scheduler.service.ts +176 -176
- package/src/_modules/scoped-config/_enums/dynts-scoped-config-level.enum.ts +22 -22
- package/src/_modules/scoped-config/_models/data-models/dynts-scoped-config.data-model.ts +82 -82
- package/src/_modules/scoped-config/_models/interfaces/dynts-scoped-config.interface.ts +107 -107
- package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.spec.ts +312 -312
- package/src/_modules/scoped-config/_services/dynts-scoped-config.control-service.ts +311 -311
- package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.spec.ts +123 -123
- package/src/_modules/scoped-config/_services/dynts-scoped-config.data-service.ts +108 -108
- package/src/_modules/scoped-config/index.ts +17 -17
- package/src/_modules/server/errors/errors.control-service.spec.ts +246 -246
- package/src/_modules/server/errors/errors.control-service.ts +100 -100
- package/src/_modules/server/errors/errors.controller.spec.ts +340 -340
- package/src/_modules/server/errors/errors.controller.ts +559 -559
- package/src/_modules/server/errors/errors.data-service.spec.ts +480 -480
- package/src/_modules/server/errors/errors.data-service.ts +867 -867
- package/src/_modules/server/index.ts +37 -27
- package/src/_modules/server/safe-diagnostic/safe-diagnostic-cause.type-enum.ts +8 -0
- package/src/_modules/server/safe-diagnostic/safe-diagnostic-stage.type-enum.ts +19 -0
- package/src/_modules/server/safe-diagnostic/safe-diagnostic.control-service.spec.ts +124 -0
- package/src/_modules/server/safe-diagnostic/safe-diagnostic.control-service.ts +99 -0
- package/src/_modules/server/safe-diagnostic/safe-diagnostic.interface.ts +20 -0
- package/src/_modules/server/server-status/db-readiness-probe-code.type-enum.ts +13 -0
- package/src/_modules/server/server-status/db-readiness-probe-stage.type-enum.ts +7 -0
- package/src/_modules/server/server-status/db-readiness-probe.control-service.spec.ts +235 -0
- package/src/_modules/server/server-status/db-readiness-probe.control-service.ts +158 -0
- package/src/_modules/server/server-status/db-readiness-probe.interface.ts +20 -0
- package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -70
- package/src/_modules/server/server-status/server-status-snapshot.control-service.ts +17 -17
- package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -77
- package/src/_modules/server/server-status/server-status-snapshot.data-service.ts +37 -37
- package/src/_modules/server/server-status/server-status.control-service.spec.ts +672 -672
- package/src/_modules/server/server-status/server-status.control-service.ts +490 -490
- package/src/_modules/server/server-status/server-status.controller.spec.ts +276 -276
- package/src/_modules/server/server-status/server-status.controller.ts +336 -336
- package/src/_modules/socket/_enums/socket-security.enum.ts +11 -11
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +32 -32
- package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +22 -22
- package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +165 -165
- package/src/_modules/socket/_models/socket-presence.control-model.ts +211 -211
- package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +69 -69
- package/src/_modules/socket/_models/socket-server-service-params.control-model.ts +33 -33
- package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -15
- package/src/_modules/socket/_services/socket-client.service.ts +260 -260
- package/src/_modules/socket/_services/socket-server.service.spec.ts +272 -272
- package/src/_modules/socket/_services/socket-server.service.ts +1037 -1037
- package/src/_modules/socket/app-extended.integration.spec.ts +85 -85
- package/src/_modules/socket/app-extended.server.ts +648 -648
- package/src/_modules/socket/index.ts +42 -42
- package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -28
- package/src/_modules/test/get-test-routing-module.util.ts +23 -23
- package/src/_modules/test/index.ts +11 -11
- package/src/_modules/test/test.controller.spec.ts +72 -72
- package/src/_modules/test/test.controller.ts +115 -115
- package/src/_modules/test-email-sink/_collections/test-email-pattern.const.ts +10 -10
- package/src/_modules/test-email-sink/_models/data-models/dynts-sent-test-mail.data-model.ts +41 -41
- package/src/_modules/test-email-sink/_services/dynts-test-email-sink.service.spec.ts +112 -112
- package/src/_modules/test-email-sink/_services/dynts-test-email-sink.service.ts +141 -141
- package/src/_modules/test-email-sink/get-sent-mail-routing-module.util.ts +29 -29
- package/src/_modules/test-email-sink/index.ts +11 -11
- package/src/_modules/test-email-sink/test-email-sink.controller.ts +83 -83
- package/src/_modules/usage/get-usage-routing-module.util.ts +22 -22
- package/src/_modules/usage/index.ts +15 -15
- package/src/_modules/usage/usage.controller.spec.ts +106 -106
- package/src/_modules/usage/usage.controller.ts +140 -140
- package/src/_modules/usage/usage.data-service.spec.ts +332 -332
- package/src/_modules/usage/usage.data-service.ts +185 -185
- package/src/_services/base/api.service-base.spec.ts +125 -125
- package/src/_services/base/api.service-base.ts +74 -74
- package/src/_services/base/archive-data.service.spec.ts +209 -209
- package/src/_services/base/archive-data.service.ts +228 -228
- package/src/_services/base/data.service.spec.ts +784 -784
- package/src/_services/base/data.service.ts +2792 -2792
- package/src/_services/base/db.service.encryption.spec.ts +76 -76
- package/src/_services/base/db.service.spec.ts +160 -160
- package/src/_services/base/db.service.ts +1698 -1698
- package/src/_services/base/singleton.service-base.spec.ts +28 -28
- package/src/_services/base/singleton.service-base.ts +24 -24
- package/src/_services/base/singleton.service.spec.ts +114 -114
- package/src/_services/base/singleton.service.ts +38 -38
- package/src/_services/core/api.service.spec.ts +187 -187
- package/src/_services/core/api.service.ts +627 -627
- package/src/_services/core/auth.service.spec.ts +159 -159
- package/src/_services/core/auth.service.ts +174 -174
- package/src/_services/core/collection-growth-monitor.service.spec.ts +119 -119
- package/src/_services/core/collection-growth-monitor.service.ts +234 -234
- package/src/_services/core/db-stats.service.ts +104 -104
- package/src/_services/core/diagnostics.service.spec.ts +44 -44
- package/src/_services/core/diagnostics.service.ts +158 -158
- package/src/_services/core/email.service.spec.ts +85 -85
- package/src/_services/core/email.service.ts +757 -757
- package/src/_services/core/event-loop-diag.service.spec.ts +22 -22
- package/src/_services/core/event-loop-diag.service.ts +144 -144
- package/src/_services/core/global.service.spec.ts +292 -292
- package/src/_services/core/global.service.ts +466 -465
- package/src/_services/core/memory-guard.service.spec.ts +245 -245
- package/src/_services/core/memory-guard.service.ts +481 -481
- package/src/_services/core/migration-runner.service.spec.ts +91 -91
- package/src/_services/core/migration-runner.service.ts +106 -106
- package/src/_services/core/mongo-transaction.control-service.spec.ts +165 -165
- package/src/_services/core/mongo-transaction.control-service.ts +148 -148
- package/src/_services/core/request-hunter.service.spec.ts +124 -124
- package/src/_services/core/request-hunter.service.ts +157 -157
- package/src/_services/core/service-collection.service.spec.ts +46 -46
- package/src/_services/core/service-collection.service.ts +6 -6
- package/src/_services/route/controller.service.spec.ts +53 -53
- package/src/_services/route/controller.service.ts +148 -148
- package/src/_services/route/routing-module.service.spec.ts +98 -98
- package/src/_services/route/routing-module.service.ts +330 -330
- package/src/_services/server/app-safe-diagnostic.spec.ts +124 -0
- package/src/_services/server/app.server-retention.spec.ts +106 -106
- package/src/_services/server/app.server.ts +1865 -1918
- package/src/_services/shared.static-service.spec.ts +99 -99
- package/src/_services/shared.static-service.ts +78 -78
- package/src/index.ts +117 -117
- package/tsconfig.app.json +12 -12
- package/tsconfig.json +42 -42
- package/.dynamo/logs/cicd-pipeline/output.log +0 -2883
- package/.dynamo/logs/cicd-pipeline/status.json +0 -74
|
@@ -1,586 +1,586 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createHash,
|
|
3
|
-
randomUUID
|
|
4
|
-
} from 'crypto';
|
|
5
|
-
|
|
6
|
-
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
7
|
-
|
|
8
|
-
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
9
|
-
import { DyNTS_PrivacyContributorAction_Type } from './_enums/privacy-contributor-action.type-enum';
|
|
10
|
-
import { DyNTS_PrivacyContributorOutcome_Type } from './_enums/privacy-contributor-outcome.type-enum';
|
|
11
|
-
import { DyNTS_PrivacyRequestState_Type } from './_enums/privacy-request-state.type-enum';
|
|
12
|
-
import { DyNTS_PrivacyRequest_Type } from './_enums/privacy-request.type-enum';
|
|
13
|
-
import { DyNTS_PrivacyContributorContext_Interface } from './_models/privacy-contributor-context.interface';
|
|
14
|
-
import { DyNTS_PrivacyContributorOutcome_Interface } from './_models/privacy-contributor-outcome.interface';
|
|
15
|
-
import { DyNTS_PrivacyContributorPlan_Interface } from './_models/privacy-contributor-plan.interface';
|
|
16
|
-
import { DyNTS_PrivacyContributor_Interface } from './_models/privacy-contributor.interface';
|
|
17
|
-
import { DyNTS_PrivacyLifecycleAdapter_Interface } from './_models/privacy-lifecycle-adapter.interface';
|
|
18
|
-
import { DyNTS_PrivacyLifecycleSettings_Interface } from './_models/privacy-lifecycle-settings.interface';
|
|
19
|
-
import { DyNTS_PrivacyRequestCreateResult_Interface } from './_models/privacy-request-create-result.interface';
|
|
20
|
-
import { DyNTS_PrivacyRequestOpen_Interface } from './_models/privacy-request-open.interface';
|
|
21
|
-
import {
|
|
22
|
-
DyNTS_PrivacyRequestPersistenceCreateResult_Interface
|
|
23
|
-
} from './_models/privacy-request-persistence-create-result.interface';
|
|
24
|
-
import { DyNTS_PrivacyRequestRecord_Interface } from './_models/privacy-request-record.interface';
|
|
25
|
-
import { DyNTS_PrivacyRequestResult_Interface } from './_models/privacy-request-result.interface';
|
|
26
|
-
import { DyNTS_PrivacyRequestView_Interface } from './_models/privacy-request-view.interface';
|
|
27
|
-
|
|
28
|
-
/** Coordinates identity-gated, resumable data-subject requests across product-owned data contributors. */
|
|
29
|
-
export class DyNTS_PrivacyLifecycle_ControlService {
|
|
30
|
-
private readonly adapter: DyNTS_PrivacyLifecycleAdapter_Interface;
|
|
31
|
-
private readonly contributors: DyNTS_PrivacyContributor_Interface[];
|
|
32
|
-
private readonly clock: () => Date;
|
|
33
|
-
|
|
34
|
-
/** Creates an orchestrator with a stable contributor registry. */
|
|
35
|
-
constructor(set: DyNTS_PrivacyLifecycleSettings_Interface) {
|
|
36
|
-
this.adapter = set.adapter;
|
|
37
|
-
this.contributors = [ ...set.contributors ]
|
|
38
|
-
.sort((first: DyNTS_PrivacyContributor_Interface, second: DyNTS_PrivacyContributor_Interface): number => (
|
|
39
|
-
first.contributorId.localeCompare(second.contributorId)
|
|
40
|
-
));
|
|
41
|
-
this.clock = set.clock ?? ((): Date => new Date());
|
|
42
|
-
this.validateSettings();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Opens or safely replays a subject-scoped request without persisting the raw idempotency key. */
|
|
46
|
-
public async openRequest(
|
|
47
|
-
set: DyNTS_PrivacyRequestOpen_Interface
|
|
48
|
-
): Promise<DyNTS_PrivacyRequestCreateResult_Interface> {
|
|
49
|
-
if (
|
|
50
|
-
!this.isBoundedText(set.subjectId, 256)
|
|
51
|
-
|| !this.isBoundedText(set.organizationId, 256)
|
|
52
|
-
|| !Object.values(DyNTS_PrivacyRequest_Type).includes(set.type)
|
|
53
|
-
) {
|
|
54
|
-
throw this.buildError(400, 'REQUEST_INVALID', 'The privacy request is invalid.');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
!this.isBoundedText(set.idempotencyKey, 256)
|
|
59
|
-
|| !this.isFutureDate(set.deadlineAt)
|
|
60
|
-
) {
|
|
61
|
-
throw this.buildError(400, 'IDEMPOTENCY_KEY_INVALID', 'The privacy request key is invalid.');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const createdAt: string = this.clock().toISOString();
|
|
65
|
-
const request: DyNTS_PrivacyRequestRecord_Interface = {
|
|
66
|
-
requestId: randomUUID(),
|
|
67
|
-
subjectId: set.subjectId,
|
|
68
|
-
organizationId: set.organizationId,
|
|
69
|
-
type: set.type,
|
|
70
|
-
state: DyNTS_PrivacyRequestState_Type.received,
|
|
71
|
-
idempotencyHash: this.hashIdempotency(set),
|
|
72
|
-
revision: 0,
|
|
73
|
-
createdAt: createdAt,
|
|
74
|
-
deadlineAt: set.deadlineAt,
|
|
75
|
-
identityVerifiedAt: '',
|
|
76
|
-
scopedAt: '',
|
|
77
|
-
plannedAt: '',
|
|
78
|
-
executionStartedAt: '',
|
|
79
|
-
verifyingStartedAt: '',
|
|
80
|
-
completedAt: '',
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const result: DyNTS_PrivacyRequestPersistenceCreateResult_Interface =
|
|
84
|
-
await this.adapter.createOrGetRequest(request);
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
result.request.idempotencyHash !== request.idempotencyHash
|
|
88
|
-
|| result.request.subjectId !== request.subjectId
|
|
89
|
-
|| result.request.organizationId !== request.organizationId
|
|
90
|
-
|| result.request.type !== request.type
|
|
91
|
-
) {
|
|
92
|
-
throw this.buildError(409, 'IDEMPOTENCY_CONFLICT', 'The idempotency key belongs to another request.');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return { request: this.toRequestView(result.request), created: result.created };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Marks request identity verified after the application has completed its security challenge. */
|
|
99
|
-
public async verifyIdentity(
|
|
100
|
-
requestId: string,
|
|
101
|
-
subjectId: string
|
|
102
|
-
): Promise<DyNTS_PrivacyRequestView_Interface> {
|
|
103
|
-
const request: DyNTS_PrivacyRequestRecord_Interface = await this.requireOwnedRequest(requestId, subjectId);
|
|
104
|
-
|
|
105
|
-
if (request.state === DyNTS_PrivacyRequestState_Type.identityVerified) {
|
|
106
|
-
return this.toRequestView(request);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (request.state !== DyNTS_PrivacyRequestState_Type.received) {
|
|
110
|
-
throw this.buildError(409, 'IDENTITY_STATE_CONFLICT', 'The request cannot be identity-verified now.');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const replacement: DyNTS_PrivacyRequestRecord_Interface = await this.replaceState(
|
|
114
|
-
request,
|
|
115
|
-
DyNTS_PrivacyRequestState_Type.identityVerified,
|
|
116
|
-
{
|
|
117
|
-
identityVerifiedAt: this.clock().toISOString(),
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
return this.toRequestView(replacement);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Executes or resumes all contributors and never reports complete while one contributor failed. */
|
|
125
|
-
public async processRequest(
|
|
126
|
-
requestId: string,
|
|
127
|
-
subjectId: string
|
|
128
|
-
): Promise<DyNTS_PrivacyRequestResult_Interface> {
|
|
129
|
-
let request: DyNTS_PrivacyRequestRecord_Interface = await this.requireOwnedRequest(requestId, subjectId);
|
|
130
|
-
|
|
131
|
-
if (request.state === DyNTS_PrivacyRequestState_Type.completed) {
|
|
132
|
-
return this.buildResult(request, await this.adapter.listContributorOutcomes(request.requestId));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
request.state !== DyNTS_PrivacyRequestState_Type.identityVerified
|
|
137
|
-
&& request.state !== DyNTS_PrivacyRequestState_Type.scoped
|
|
138
|
-
&& request.state !== DyNTS_PrivacyRequestState_Type.planned
|
|
139
|
-
&& request.state !== DyNTS_PrivacyRequestState_Type.executing
|
|
140
|
-
&& request.state !== DyNTS_PrivacyRequestState_Type.verifying
|
|
141
|
-
&& request.state !== DyNTS_PrivacyRequestState_Type.partiallyCompleted
|
|
142
|
-
) {
|
|
143
|
-
throw this.buildError(409, 'EXECUTION_STATE_CONFLICT', 'The request is not ready for execution.');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (request.state === DyNTS_PrivacyRequestState_Type.identityVerified) {
|
|
147
|
-
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.scoped, {
|
|
148
|
-
scopedAt: this.clock().toISOString(),
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const context: DyNTS_PrivacyContributorContext_Interface = this.buildContext(request);
|
|
153
|
-
let plans: DyNTS_PrivacyContributorPlan_Interface[] = await this.adapter.listContributorPlans(request.requestId);
|
|
154
|
-
|
|
155
|
-
this.validateStoredPlans(plans);
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
request.state === DyNTS_PrivacyRequestState_Type.scoped
|
|
159
|
-
|| request.state === DyNTS_PrivacyRequestState_Type.partiallyCompleted
|
|
160
|
-
) {
|
|
161
|
-
await this.planMissingContributors(request.requestId, context, plans);
|
|
162
|
-
plans = await this.adapter.listContributorPlans(request.requestId);
|
|
163
|
-
this.validateStoredPlans(plans);
|
|
164
|
-
|
|
165
|
-
if (!this.hasAllContributorPlans(plans)) {
|
|
166
|
-
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.partiallyCompleted, {
|
|
167
|
-
completedAt: '',
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
return this.buildResult(request, await this.adapter.listContributorOutcomes(request.requestId));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.planned, {
|
|
174
|
-
plannedAt: this.clock().toISOString(),
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (request.state === DyNTS_PrivacyRequestState_Type.planned) {
|
|
179
|
-
this.validateStoredPlans(plans);
|
|
180
|
-
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.executing, {
|
|
181
|
-
executionStartedAt: request.executionStartedAt || this.clock().toISOString(),
|
|
182
|
-
completedAt: '',
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (request.state === DyNTS_PrivacyRequestState_Type.executing) {
|
|
187
|
-
await this.executeMissingContributors(request.requestId, context, plans);
|
|
188
|
-
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.verifying, {
|
|
189
|
-
verifyingStartedAt: this.clock().toISOString(),
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
let outcomes: DyNTS_PrivacyContributorOutcome_Interface[] =
|
|
194
|
-
await this.adapter.listContributorOutcomes(request.requestId);
|
|
195
|
-
|
|
196
|
-
if (request.state === DyNTS_PrivacyRequestState_Type.verifying) {
|
|
197
|
-
await this.verifyContributorOutcomes(context, plans, outcomes);
|
|
198
|
-
outcomes = await this.adapter.listContributorOutcomes(request.requestId);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const isComplete: boolean = this.contributors.every((contributor: DyNTS_PrivacyContributor_Interface): boolean => (
|
|
202
|
-
outcomes.some((outcome: DyNTS_PrivacyContributorOutcome_Interface): boolean => (
|
|
203
|
-
outcome.contributorId === contributor.contributorId
|
|
204
|
-
&& outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed
|
|
205
|
-
))
|
|
206
|
-
));
|
|
207
|
-
const finalState: DyNTS_PrivacyRequestState_Type = isComplete
|
|
208
|
-
? DyNTS_PrivacyRequestState_Type.completed
|
|
209
|
-
: DyNTS_PrivacyRequestState_Type.partiallyCompleted;
|
|
210
|
-
|
|
211
|
-
request = await this.replaceState(request, finalState, {
|
|
212
|
-
completedAt: isComplete ? this.clock().toISOString() : '',
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
return this.buildResult(request, outcomes);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** Returns an owned request and its content-free contributor outcomes. */
|
|
219
|
-
public async getRequest(
|
|
220
|
-
requestId: string,
|
|
221
|
-
subjectId: string
|
|
222
|
-
): Promise<DyNTS_PrivacyRequestResult_Interface> {
|
|
223
|
-
const request: DyNTS_PrivacyRequestRecord_Interface = await this.requireOwnedRequest(requestId, subjectId);
|
|
224
|
-
|
|
225
|
-
return this.buildResult(request, await this.adapter.listContributorOutcomes(request.requestId));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
private async planMissingContributors(
|
|
229
|
-
requestId: string,
|
|
230
|
-
context: DyNTS_PrivacyContributorContext_Interface,
|
|
231
|
-
existingPlans: DyNTS_PrivacyContributorPlan_Interface[]
|
|
232
|
-
): Promise<void> {
|
|
233
|
-
const plannedContributorIds: Set<string> = new Set(existingPlans.map((
|
|
234
|
-
plan: DyNTS_PrivacyContributorPlan_Interface
|
|
235
|
-
): string => plan.contributorId));
|
|
236
|
-
|
|
237
|
-
for (const contributor of this.contributors) {
|
|
238
|
-
if (plannedContributorIds.has(contributor.contributorId)) {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
try {
|
|
243
|
-
const plan: DyNTS_PrivacyContributorPlan_Interface = await contributor.plan(context);
|
|
244
|
-
|
|
245
|
-
this.validatePlan(contributor, plan);
|
|
246
|
-
await this.adapter.saveContributorPlan(requestId, plan);
|
|
247
|
-
} catch (error: unknown) {
|
|
248
|
-
await this.adapter.saveContributorOutcome(requestId, this.buildFailedOutcome(
|
|
249
|
-
contributor.contributorId,
|
|
250
|
-
DyNTS_PrivacyContributorAction_Type.noData,
|
|
251
|
-
error instanceof DyFM_Error ? 'CONTRIBUTOR_PLAN_INVALID' : 'CONTRIBUTOR_PLAN_FAILED'
|
|
252
|
-
));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private async executeMissingContributors(
|
|
258
|
-
requestId: string,
|
|
259
|
-
context: DyNTS_PrivacyContributorContext_Interface,
|
|
260
|
-
plans: DyNTS_PrivacyContributorPlan_Interface[]
|
|
261
|
-
): Promise<void> {
|
|
262
|
-
const existing: DyNTS_PrivacyContributorOutcome_Interface[] =
|
|
263
|
-
await this.adapter.listContributorOutcomes(requestId);
|
|
264
|
-
const completedContributorIds: Set<string> = new Set();
|
|
265
|
-
|
|
266
|
-
for (const contributor of this.contributors) {
|
|
267
|
-
const plan: DyNTS_PrivacyContributorPlan_Interface | undefined = plans.find((
|
|
268
|
-
item: DyNTS_PrivacyContributorPlan_Interface
|
|
269
|
-
): boolean => item.contributorId === contributor.contributorId);
|
|
270
|
-
const outcome: DyNTS_PrivacyContributorOutcome_Interface | undefined = existing.find((
|
|
271
|
-
item: DyNTS_PrivacyContributorOutcome_Interface
|
|
272
|
-
): boolean => item.contributorId === contributor.contributorId);
|
|
273
|
-
|
|
274
|
-
if (plan && outcome && this.isValidCompletedOutcome(contributor, plan, outcome)) {
|
|
275
|
-
completedContributorIds.add(contributor.contributorId);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
for (const contributor of this.contributors) {
|
|
280
|
-
if (completedContributorIds.has(contributor.contributorId)) {
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const plan: DyNTS_PrivacyContributorPlan_Interface | undefined = plans.find((
|
|
285
|
-
item: DyNTS_PrivacyContributorPlan_Interface
|
|
286
|
-
): boolean => item.contributorId === contributor.contributorId);
|
|
287
|
-
const outcome: DyNTS_PrivacyContributorOutcome_Interface = plan
|
|
288
|
-
? await this.executeContributor(contributor, context, plan)
|
|
289
|
-
: this.buildFailedOutcome(
|
|
290
|
-
contributor.contributorId,
|
|
291
|
-
DyNTS_PrivacyContributorAction_Type.noData,
|
|
292
|
-
'CONTRIBUTOR_PLAN_MISSING'
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
await this.adapter.saveContributorOutcome(requestId, outcome);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
private async executeContributor(
|
|
300
|
-
contributor: DyNTS_PrivacyContributor_Interface,
|
|
301
|
-
context: DyNTS_PrivacyContributorContext_Interface,
|
|
302
|
-
plan: DyNTS_PrivacyContributorPlan_Interface
|
|
303
|
-
): Promise<DyNTS_PrivacyContributorOutcome_Interface> {
|
|
304
|
-
try {
|
|
305
|
-
const outcome: DyNTS_PrivacyContributorOutcome_Interface = await contributor.execute(context, plan);
|
|
306
|
-
|
|
307
|
-
this.validateOutcome(contributor, plan, outcome);
|
|
308
|
-
|
|
309
|
-
return { ...outcome };
|
|
310
|
-
} catch (error: unknown) {
|
|
311
|
-
return this.buildFailedOutcome(
|
|
312
|
-
contributor.contributorId,
|
|
313
|
-
plan.action,
|
|
314
|
-
error instanceof DyFM_Error ? 'CONTRIBUTOR_CONTRACT_FAILED' : 'CONTRIBUTOR_EXECUTION_FAILED'
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
private async verifyContributorOutcomes(
|
|
320
|
-
context: DyNTS_PrivacyContributorContext_Interface,
|
|
321
|
-
plans: DyNTS_PrivacyContributorPlan_Interface[],
|
|
322
|
-
outcomes: DyNTS_PrivacyContributorOutcome_Interface[]
|
|
323
|
-
): Promise<void> {
|
|
324
|
-
for (const contributor of this.contributors) {
|
|
325
|
-
const outcome: DyNTS_PrivacyContributorOutcome_Interface | undefined = outcomes.find((
|
|
326
|
-
item: DyNTS_PrivacyContributorOutcome_Interface
|
|
327
|
-
): boolean => item.contributorId === contributor.contributorId);
|
|
328
|
-
const plan: DyNTS_PrivacyContributorPlan_Interface | undefined = plans.find((
|
|
329
|
-
item: DyNTS_PrivacyContributorPlan_Interface
|
|
330
|
-
): boolean => item.contributorId === contributor.contributorId);
|
|
331
|
-
|
|
332
|
-
if (!outcome || outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.failed || !plan) {
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
try {
|
|
337
|
-
this.validateOutcome(contributor, plan, outcome);
|
|
338
|
-
|
|
339
|
-
if (!await contributor.verify(context, outcome)) {
|
|
340
|
-
await this.adapter.saveContributorOutcome(context.requestId, this.buildFailedOutcome(
|
|
341
|
-
contributor.contributorId,
|
|
342
|
-
outcome.action,
|
|
343
|
-
'CONTRIBUTOR_VERIFY_FAILED'
|
|
344
|
-
));
|
|
345
|
-
}
|
|
346
|
-
} catch {
|
|
347
|
-
await this.adapter.saveContributorOutcome(context.requestId, this.buildFailedOutcome(
|
|
348
|
-
contributor.contributorId,
|
|
349
|
-
outcome.action,
|
|
350
|
-
'CONTRIBUTOR_VERIFY_FAILED'
|
|
351
|
-
));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
private validatePlan(
|
|
357
|
-
contributor: DyNTS_PrivacyContributor_Interface,
|
|
358
|
-
plan: DyNTS_PrivacyContributorPlan_Interface
|
|
359
|
-
): void {
|
|
360
|
-
if (
|
|
361
|
-
plan.contributorId !== contributor.contributorId
|
|
362
|
-
|| !this.isBoundedText(plan.contributorId, 128)
|
|
363
|
-
|| !Object.values(DyNTS_PrivacyContributorAction_Type).includes(plan.action)
|
|
364
|
-
|| (plan.action === DyNTS_PrivacyContributorAction_Type.retainWithBasis && !plan.retentionBasisCode)
|
|
365
|
-
|| (plan.action !== DyNTS_PrivacyContributorAction_Type.retainWithBasis && !!plan.retentionBasisCode)
|
|
366
|
-
) {
|
|
367
|
-
throw this.buildError(500, 'CONTRIBUTOR_PLAN_INVALID', 'A privacy contributor returned an invalid plan.');
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
private validateOutcome(
|
|
372
|
-
contributor: DyNTS_PrivacyContributor_Interface,
|
|
373
|
-
plan: DyNTS_PrivacyContributorPlan_Interface,
|
|
374
|
-
outcome: DyNTS_PrivacyContributorOutcome_Interface
|
|
375
|
-
): void {
|
|
376
|
-
if (
|
|
377
|
-
outcome.contributorId !== contributor.contributorId
|
|
378
|
-
|| outcome.action !== plan.action
|
|
379
|
-
|| !Object.values(DyNTS_PrivacyContributorOutcome_Type).includes(outcome.outcome)
|
|
380
|
-
|| !Number.isSafeInteger(outcome.processedRecordCount)
|
|
381
|
-
|| outcome.processedRecordCount < 0
|
|
382
|
-
|| (outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis
|
|
383
|
-
&& outcome.retentionBasisCode !== plan.retentionBasisCode)
|
|
384
|
-
|| (outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis
|
|
385
|
-
&& !!outcome.retentionBasisCode)
|
|
386
|
-
|| (outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.failed && !outcome.errorCode)
|
|
387
|
-
|| (outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed && !!outcome.errorCode)
|
|
388
|
-
|| (outcome.action === DyNTS_PrivacyContributorAction_Type.retainWithBasis
|
|
389
|
-
&& outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis
|
|
390
|
-
&& outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed)
|
|
391
|
-
|| (outcome.action !== DyNTS_PrivacyContributorAction_Type.retainWithBasis
|
|
392
|
-
&& outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis)
|
|
393
|
-
|| (!!outcome.artifactChecksum && !/^[a-f0-9]{64}$/u.test(outcome.artifactChecksum))
|
|
394
|
-
|| !Number.isFinite(new Date(outcome.completedAt).getTime())
|
|
395
|
-
) {
|
|
396
|
-
throw this.buildError(500, 'CONTRIBUTOR_OUTCOME_INVALID', 'A privacy contributor returned an invalid outcome.');
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
private buildFailedOutcome(
|
|
401
|
-
contributorId: string,
|
|
402
|
-
action: DyNTS_PrivacyContributorAction_Type,
|
|
403
|
-
errorCode: string
|
|
404
|
-
): DyNTS_PrivacyContributorOutcome_Interface {
|
|
405
|
-
return {
|
|
406
|
-
contributorId: contributorId,
|
|
407
|
-
action: action,
|
|
408
|
-
outcome: DyNTS_PrivacyContributorOutcome_Type.failed,
|
|
409
|
-
retentionBasisCode: '',
|
|
410
|
-
artifactChecksum: '',
|
|
411
|
-
processedRecordCount: 0,
|
|
412
|
-
errorCode: errorCode,
|
|
413
|
-
completedAt: this.clock().toISOString(),
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
private async requireOwnedRequest(
|
|
418
|
-
requestId: string,
|
|
419
|
-
subjectId: string
|
|
420
|
-
): Promise<DyNTS_PrivacyRequestRecord_Interface> {
|
|
421
|
-
const request: DyNTS_PrivacyRequestRecord_Interface | null = await this.adapter.findRequestById(requestId);
|
|
422
|
-
|
|
423
|
-
if (request?.subjectId !== subjectId) {
|
|
424
|
-
throw this.buildError(404, 'REQUEST_NOT_FOUND', 'The privacy request was not found.');
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return request;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
private async replaceState(
|
|
431
|
-
request: DyNTS_PrivacyRequestRecord_Interface,
|
|
432
|
-
state: DyNTS_PrivacyRequestState_Type,
|
|
433
|
-
dates: {
|
|
434
|
-
identityVerifiedAt?: string;
|
|
435
|
-
scopedAt?: string;
|
|
436
|
-
plannedAt?: string;
|
|
437
|
-
executionStartedAt?: string;
|
|
438
|
-
verifyingStartedAt?: string;
|
|
439
|
-
completedAt?: string;
|
|
440
|
-
}
|
|
441
|
-
): Promise<DyNTS_PrivacyRequestRecord_Interface> {
|
|
442
|
-
const replacement: DyNTS_PrivacyRequestRecord_Interface = {
|
|
443
|
-
...request,
|
|
444
|
-
...dates,
|
|
445
|
-
state: state,
|
|
446
|
-
revision: request.revision + 1,
|
|
447
|
-
};
|
|
448
|
-
const didReplace: boolean = await this.adapter.replaceRequest(replacement, request.revision);
|
|
449
|
-
|
|
450
|
-
if (!didReplace) {
|
|
451
|
-
throw this.buildError(409, 'REQUEST_REVISION_CONFLICT', 'The privacy request changed concurrently.');
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
return replacement;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
private buildContext(request: DyNTS_PrivacyRequestRecord_Interface): DyNTS_PrivacyContributorContext_Interface {
|
|
458
|
-
return {
|
|
459
|
-
requestId: request.requestId,
|
|
460
|
-
subjectId: request.subjectId,
|
|
461
|
-
organizationId: request.organizationId,
|
|
462
|
-
type: request.type,
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
private buildResult(
|
|
467
|
-
request: DyNTS_PrivacyRequestRecord_Interface,
|
|
468
|
-
outcomes: DyNTS_PrivacyContributorOutcome_Interface[]
|
|
469
|
-
): DyNTS_PrivacyRequestResult_Interface {
|
|
470
|
-
if (outcomes.some((outcome: DyNTS_PrivacyContributorOutcome_Interface): boolean => (
|
|
471
|
-
!this.contributors.some((contributor: DyNTS_PrivacyContributor_Interface): boolean => (
|
|
472
|
-
contributor.contributorId === outcome.contributorId
|
|
473
|
-
))
|
|
474
|
-
))) {
|
|
475
|
-
throw this.buildError(500, 'CONTRIBUTOR_OUTCOME_UNKNOWN', 'An unknown contributor outcome was stored.');
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
return {
|
|
479
|
-
request: this.toRequestView(request),
|
|
480
|
-
outcomes: [ ...outcomes ].sort((
|
|
481
|
-
first: DyNTS_PrivacyContributorOutcome_Interface,
|
|
482
|
-
second: DyNTS_PrivacyContributorOutcome_Interface
|
|
483
|
-
): number => (
|
|
484
|
-
first.contributorId.localeCompare(second.contributorId)
|
|
485
|
-
)),
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
private toRequestView(request: DyNTS_PrivacyRequestRecord_Interface): DyNTS_PrivacyRequestView_Interface {
|
|
490
|
-
return {
|
|
491
|
-
requestId: request.requestId,
|
|
492
|
-
subjectId: request.subjectId,
|
|
493
|
-
organizationId: request.organizationId,
|
|
494
|
-
type: request.type,
|
|
495
|
-
state: request.state,
|
|
496
|
-
revision: request.revision,
|
|
497
|
-
createdAt: request.createdAt,
|
|
498
|
-
deadlineAt: request.deadlineAt,
|
|
499
|
-
identityVerifiedAt: request.identityVerifiedAt,
|
|
500
|
-
scopedAt: request.scopedAt,
|
|
501
|
-
plannedAt: request.plannedAt,
|
|
502
|
-
executionStartedAt: request.executionStartedAt,
|
|
503
|
-
verifyingStartedAt: request.verifyingStartedAt,
|
|
504
|
-
completedAt: request.completedAt,
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
private hashIdempotency(set: DyNTS_PrivacyRequestOpen_Interface): string {
|
|
509
|
-
return createHash('sha256')
|
|
510
|
-
.update(`${set.subjectId}\u0000${set.organizationId}\u0000${set.type}\u0000${set.idempotencyKey}`)
|
|
511
|
-
.digest('hex');
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
private isFutureDate(value: string): boolean {
|
|
515
|
-
const timestamp: number = new Date(value).getTime();
|
|
516
|
-
|
|
517
|
-
return Number.isFinite(timestamp) && timestamp > this.clock().getTime();
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
private isBoundedText(value: string, maxLength: number): boolean {
|
|
521
|
-
return typeof value === 'string' && !!value && value.length <= maxLength && !value.includes('\u0000');
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
private hasAllContributorPlans(plans: DyNTS_PrivacyContributorPlan_Interface[]): boolean {
|
|
525
|
-
return this.contributors.every((contributor: DyNTS_PrivacyContributor_Interface): boolean => (
|
|
526
|
-
plans.some((plan: DyNTS_PrivacyContributorPlan_Interface): boolean => (
|
|
527
|
-
plan.contributorId === contributor.contributorId
|
|
528
|
-
))
|
|
529
|
-
));
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
private validateStoredPlans(plans: DyNTS_PrivacyContributorPlan_Interface[]): void {
|
|
533
|
-
for (const plan of plans) {
|
|
534
|
-
const contributor: DyNTS_PrivacyContributor_Interface | undefined = this.contributors.find((
|
|
535
|
-
item: DyNTS_PrivacyContributor_Interface
|
|
536
|
-
): boolean => item.contributorId === plan.contributorId);
|
|
537
|
-
|
|
538
|
-
if (!contributor) {
|
|
539
|
-
throw this.buildError(500, 'CONTRIBUTOR_PLAN_UNKNOWN', 'An unknown privacy contributor plan was stored.');
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
this.validatePlan(contributor, plan);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
private isValidCompletedOutcome(
|
|
547
|
-
contributor: DyNTS_PrivacyContributor_Interface,
|
|
548
|
-
plan: DyNTS_PrivacyContributorPlan_Interface,
|
|
549
|
-
outcome: DyNTS_PrivacyContributorOutcome_Interface
|
|
550
|
-
): boolean {
|
|
551
|
-
try {
|
|
552
|
-
this.validateOutcome(contributor, plan, outcome);
|
|
553
|
-
|
|
554
|
-
return outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed;
|
|
555
|
-
} catch {
|
|
556
|
-
return false;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
private validateSettings(): void {
|
|
561
|
-
const contributorIds: string[] = this.contributors.map((item: DyNTS_PrivacyContributor_Interface): string => (
|
|
562
|
-
item.contributorId
|
|
563
|
-
));
|
|
564
|
-
|
|
565
|
-
if (
|
|
566
|
-
!this.adapter
|
|
567
|
-
|| !this.contributors.length
|
|
568
|
-
|| contributorIds.some((contributorId: string): boolean => !contributorId)
|
|
569
|
-
|| new Set(contributorIds).size !== contributorIds.length
|
|
570
|
-
) {
|
|
571
|
-
throw this.buildError(500, 'SETTINGS_INVALID', 'The privacy lifecycle settings are invalid.');
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
private buildError(status: number, errorCode: string, message: string): DyFM_Error {
|
|
576
|
-
return new DyFM_Error({
|
|
577
|
-
status: status,
|
|
578
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|PRIVACY_LIFECYCLE|${errorCode}`,
|
|
579
|
-
message: message,
|
|
580
|
-
userMessage: status < 500
|
|
581
|
-
? message
|
|
582
|
-
: 'The privacy request could not be processed safely. Please try again later.',
|
|
583
|
-
issuerService: this.constructor.name,
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createHash,
|
|
3
|
+
randomUUID
|
|
4
|
+
} from 'crypto';
|
|
5
|
+
|
|
6
|
+
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
7
|
+
|
|
8
|
+
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
9
|
+
import { DyNTS_PrivacyContributorAction_Type } from './_enums/privacy-contributor-action.type-enum';
|
|
10
|
+
import { DyNTS_PrivacyContributorOutcome_Type } from './_enums/privacy-contributor-outcome.type-enum';
|
|
11
|
+
import { DyNTS_PrivacyRequestState_Type } from './_enums/privacy-request-state.type-enum';
|
|
12
|
+
import { DyNTS_PrivacyRequest_Type } from './_enums/privacy-request.type-enum';
|
|
13
|
+
import { DyNTS_PrivacyContributorContext_Interface } from './_models/privacy-contributor-context.interface';
|
|
14
|
+
import { DyNTS_PrivacyContributorOutcome_Interface } from './_models/privacy-contributor-outcome.interface';
|
|
15
|
+
import { DyNTS_PrivacyContributorPlan_Interface } from './_models/privacy-contributor-plan.interface';
|
|
16
|
+
import { DyNTS_PrivacyContributor_Interface } from './_models/privacy-contributor.interface';
|
|
17
|
+
import { DyNTS_PrivacyLifecycleAdapter_Interface } from './_models/privacy-lifecycle-adapter.interface';
|
|
18
|
+
import { DyNTS_PrivacyLifecycleSettings_Interface } from './_models/privacy-lifecycle-settings.interface';
|
|
19
|
+
import { DyNTS_PrivacyRequestCreateResult_Interface } from './_models/privacy-request-create-result.interface';
|
|
20
|
+
import { DyNTS_PrivacyRequestOpen_Interface } from './_models/privacy-request-open.interface';
|
|
21
|
+
import {
|
|
22
|
+
DyNTS_PrivacyRequestPersistenceCreateResult_Interface
|
|
23
|
+
} from './_models/privacy-request-persistence-create-result.interface';
|
|
24
|
+
import { DyNTS_PrivacyRequestRecord_Interface } from './_models/privacy-request-record.interface';
|
|
25
|
+
import { DyNTS_PrivacyRequestResult_Interface } from './_models/privacy-request-result.interface';
|
|
26
|
+
import { DyNTS_PrivacyRequestView_Interface } from './_models/privacy-request-view.interface';
|
|
27
|
+
|
|
28
|
+
/** Coordinates identity-gated, resumable data-subject requests across product-owned data contributors. */
|
|
29
|
+
export class DyNTS_PrivacyLifecycle_ControlService {
|
|
30
|
+
private readonly adapter: DyNTS_PrivacyLifecycleAdapter_Interface;
|
|
31
|
+
private readonly contributors: DyNTS_PrivacyContributor_Interface[];
|
|
32
|
+
private readonly clock: () => Date;
|
|
33
|
+
|
|
34
|
+
/** Creates an orchestrator with a stable contributor registry. */
|
|
35
|
+
constructor(set: DyNTS_PrivacyLifecycleSettings_Interface) {
|
|
36
|
+
this.adapter = set.adapter;
|
|
37
|
+
this.contributors = [ ...set.contributors ]
|
|
38
|
+
.sort((first: DyNTS_PrivacyContributor_Interface, second: DyNTS_PrivacyContributor_Interface): number => (
|
|
39
|
+
first.contributorId.localeCompare(second.contributorId)
|
|
40
|
+
));
|
|
41
|
+
this.clock = set.clock ?? ((): Date => new Date());
|
|
42
|
+
this.validateSettings();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Opens or safely replays a subject-scoped request without persisting the raw idempotency key. */
|
|
46
|
+
public async openRequest(
|
|
47
|
+
set: DyNTS_PrivacyRequestOpen_Interface
|
|
48
|
+
): Promise<DyNTS_PrivacyRequestCreateResult_Interface> {
|
|
49
|
+
if (
|
|
50
|
+
!this.isBoundedText(set.subjectId, 256)
|
|
51
|
+
|| !this.isBoundedText(set.organizationId, 256)
|
|
52
|
+
|| !Object.values(DyNTS_PrivacyRequest_Type).includes(set.type)
|
|
53
|
+
) {
|
|
54
|
+
throw this.buildError(400, 'REQUEST_INVALID', 'The privacy request is invalid.');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
!this.isBoundedText(set.idempotencyKey, 256)
|
|
59
|
+
|| !this.isFutureDate(set.deadlineAt)
|
|
60
|
+
) {
|
|
61
|
+
throw this.buildError(400, 'IDEMPOTENCY_KEY_INVALID', 'The privacy request key is invalid.');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const createdAt: string = this.clock().toISOString();
|
|
65
|
+
const request: DyNTS_PrivacyRequestRecord_Interface = {
|
|
66
|
+
requestId: randomUUID(),
|
|
67
|
+
subjectId: set.subjectId,
|
|
68
|
+
organizationId: set.organizationId,
|
|
69
|
+
type: set.type,
|
|
70
|
+
state: DyNTS_PrivacyRequestState_Type.received,
|
|
71
|
+
idempotencyHash: this.hashIdempotency(set),
|
|
72
|
+
revision: 0,
|
|
73
|
+
createdAt: createdAt,
|
|
74
|
+
deadlineAt: set.deadlineAt,
|
|
75
|
+
identityVerifiedAt: '',
|
|
76
|
+
scopedAt: '',
|
|
77
|
+
plannedAt: '',
|
|
78
|
+
executionStartedAt: '',
|
|
79
|
+
verifyingStartedAt: '',
|
|
80
|
+
completedAt: '',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const result: DyNTS_PrivacyRequestPersistenceCreateResult_Interface =
|
|
84
|
+
await this.adapter.createOrGetRequest(request);
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
result.request.idempotencyHash !== request.idempotencyHash
|
|
88
|
+
|| result.request.subjectId !== request.subjectId
|
|
89
|
+
|| result.request.organizationId !== request.organizationId
|
|
90
|
+
|| result.request.type !== request.type
|
|
91
|
+
) {
|
|
92
|
+
throw this.buildError(409, 'IDEMPOTENCY_CONFLICT', 'The idempotency key belongs to another request.');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { request: this.toRequestView(result.request), created: result.created };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Marks request identity verified after the application has completed its security challenge. */
|
|
99
|
+
public async verifyIdentity(
|
|
100
|
+
requestId: string,
|
|
101
|
+
subjectId: string
|
|
102
|
+
): Promise<DyNTS_PrivacyRequestView_Interface> {
|
|
103
|
+
const request: DyNTS_PrivacyRequestRecord_Interface = await this.requireOwnedRequest(requestId, subjectId);
|
|
104
|
+
|
|
105
|
+
if (request.state === DyNTS_PrivacyRequestState_Type.identityVerified) {
|
|
106
|
+
return this.toRequestView(request);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (request.state !== DyNTS_PrivacyRequestState_Type.received) {
|
|
110
|
+
throw this.buildError(409, 'IDENTITY_STATE_CONFLICT', 'The request cannot be identity-verified now.');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const replacement: DyNTS_PrivacyRequestRecord_Interface = await this.replaceState(
|
|
114
|
+
request,
|
|
115
|
+
DyNTS_PrivacyRequestState_Type.identityVerified,
|
|
116
|
+
{
|
|
117
|
+
identityVerifiedAt: this.clock().toISOString(),
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return this.toRequestView(replacement);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Executes or resumes all contributors and never reports complete while one contributor failed. */
|
|
125
|
+
public async processRequest(
|
|
126
|
+
requestId: string,
|
|
127
|
+
subjectId: string
|
|
128
|
+
): Promise<DyNTS_PrivacyRequestResult_Interface> {
|
|
129
|
+
let request: DyNTS_PrivacyRequestRecord_Interface = await this.requireOwnedRequest(requestId, subjectId);
|
|
130
|
+
|
|
131
|
+
if (request.state === DyNTS_PrivacyRequestState_Type.completed) {
|
|
132
|
+
return this.buildResult(request, await this.adapter.listContributorOutcomes(request.requestId));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (
|
|
136
|
+
request.state !== DyNTS_PrivacyRequestState_Type.identityVerified
|
|
137
|
+
&& request.state !== DyNTS_PrivacyRequestState_Type.scoped
|
|
138
|
+
&& request.state !== DyNTS_PrivacyRequestState_Type.planned
|
|
139
|
+
&& request.state !== DyNTS_PrivacyRequestState_Type.executing
|
|
140
|
+
&& request.state !== DyNTS_PrivacyRequestState_Type.verifying
|
|
141
|
+
&& request.state !== DyNTS_PrivacyRequestState_Type.partiallyCompleted
|
|
142
|
+
) {
|
|
143
|
+
throw this.buildError(409, 'EXECUTION_STATE_CONFLICT', 'The request is not ready for execution.');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (request.state === DyNTS_PrivacyRequestState_Type.identityVerified) {
|
|
147
|
+
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.scoped, {
|
|
148
|
+
scopedAt: this.clock().toISOString(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const context: DyNTS_PrivacyContributorContext_Interface = this.buildContext(request);
|
|
153
|
+
let plans: DyNTS_PrivacyContributorPlan_Interface[] = await this.adapter.listContributorPlans(request.requestId);
|
|
154
|
+
|
|
155
|
+
this.validateStoredPlans(plans);
|
|
156
|
+
|
|
157
|
+
if (
|
|
158
|
+
request.state === DyNTS_PrivacyRequestState_Type.scoped
|
|
159
|
+
|| request.state === DyNTS_PrivacyRequestState_Type.partiallyCompleted
|
|
160
|
+
) {
|
|
161
|
+
await this.planMissingContributors(request.requestId, context, plans);
|
|
162
|
+
plans = await this.adapter.listContributorPlans(request.requestId);
|
|
163
|
+
this.validateStoredPlans(plans);
|
|
164
|
+
|
|
165
|
+
if (!this.hasAllContributorPlans(plans)) {
|
|
166
|
+
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.partiallyCompleted, {
|
|
167
|
+
completedAt: '',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return this.buildResult(request, await this.adapter.listContributorOutcomes(request.requestId));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.planned, {
|
|
174
|
+
plannedAt: this.clock().toISOString(),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (request.state === DyNTS_PrivacyRequestState_Type.planned) {
|
|
179
|
+
this.validateStoredPlans(plans);
|
|
180
|
+
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.executing, {
|
|
181
|
+
executionStartedAt: request.executionStartedAt || this.clock().toISOString(),
|
|
182
|
+
completedAt: '',
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (request.state === DyNTS_PrivacyRequestState_Type.executing) {
|
|
187
|
+
await this.executeMissingContributors(request.requestId, context, plans);
|
|
188
|
+
request = await this.replaceState(request, DyNTS_PrivacyRequestState_Type.verifying, {
|
|
189
|
+
verifyingStartedAt: this.clock().toISOString(),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let outcomes: DyNTS_PrivacyContributorOutcome_Interface[] =
|
|
194
|
+
await this.adapter.listContributorOutcomes(request.requestId);
|
|
195
|
+
|
|
196
|
+
if (request.state === DyNTS_PrivacyRequestState_Type.verifying) {
|
|
197
|
+
await this.verifyContributorOutcomes(context, plans, outcomes);
|
|
198
|
+
outcomes = await this.adapter.listContributorOutcomes(request.requestId);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const isComplete: boolean = this.contributors.every((contributor: DyNTS_PrivacyContributor_Interface): boolean => (
|
|
202
|
+
outcomes.some((outcome: DyNTS_PrivacyContributorOutcome_Interface): boolean => (
|
|
203
|
+
outcome.contributorId === contributor.contributorId
|
|
204
|
+
&& outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed
|
|
205
|
+
))
|
|
206
|
+
));
|
|
207
|
+
const finalState: DyNTS_PrivacyRequestState_Type = isComplete
|
|
208
|
+
? DyNTS_PrivacyRequestState_Type.completed
|
|
209
|
+
: DyNTS_PrivacyRequestState_Type.partiallyCompleted;
|
|
210
|
+
|
|
211
|
+
request = await this.replaceState(request, finalState, {
|
|
212
|
+
completedAt: isComplete ? this.clock().toISOString() : '',
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
return this.buildResult(request, outcomes);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Returns an owned request and its content-free contributor outcomes. */
|
|
219
|
+
public async getRequest(
|
|
220
|
+
requestId: string,
|
|
221
|
+
subjectId: string
|
|
222
|
+
): Promise<DyNTS_PrivacyRequestResult_Interface> {
|
|
223
|
+
const request: DyNTS_PrivacyRequestRecord_Interface = await this.requireOwnedRequest(requestId, subjectId);
|
|
224
|
+
|
|
225
|
+
return this.buildResult(request, await this.adapter.listContributorOutcomes(request.requestId));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private async planMissingContributors(
|
|
229
|
+
requestId: string,
|
|
230
|
+
context: DyNTS_PrivacyContributorContext_Interface,
|
|
231
|
+
existingPlans: DyNTS_PrivacyContributorPlan_Interface[]
|
|
232
|
+
): Promise<void> {
|
|
233
|
+
const plannedContributorIds: Set<string> = new Set(existingPlans.map((
|
|
234
|
+
plan: DyNTS_PrivacyContributorPlan_Interface
|
|
235
|
+
): string => plan.contributorId));
|
|
236
|
+
|
|
237
|
+
for (const contributor of this.contributors) {
|
|
238
|
+
if (plannedContributorIds.has(contributor.contributorId)) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
try {
|
|
243
|
+
const plan: DyNTS_PrivacyContributorPlan_Interface = await contributor.plan(context);
|
|
244
|
+
|
|
245
|
+
this.validatePlan(contributor, plan);
|
|
246
|
+
await this.adapter.saveContributorPlan(requestId, plan);
|
|
247
|
+
} catch (error: unknown) {
|
|
248
|
+
await this.adapter.saveContributorOutcome(requestId, this.buildFailedOutcome(
|
|
249
|
+
contributor.contributorId,
|
|
250
|
+
DyNTS_PrivacyContributorAction_Type.noData,
|
|
251
|
+
error instanceof DyFM_Error ? 'CONTRIBUTOR_PLAN_INVALID' : 'CONTRIBUTOR_PLAN_FAILED'
|
|
252
|
+
));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private async executeMissingContributors(
|
|
258
|
+
requestId: string,
|
|
259
|
+
context: DyNTS_PrivacyContributorContext_Interface,
|
|
260
|
+
plans: DyNTS_PrivacyContributorPlan_Interface[]
|
|
261
|
+
): Promise<void> {
|
|
262
|
+
const existing: DyNTS_PrivacyContributorOutcome_Interface[] =
|
|
263
|
+
await this.adapter.listContributorOutcomes(requestId);
|
|
264
|
+
const completedContributorIds: Set<string> = new Set();
|
|
265
|
+
|
|
266
|
+
for (const contributor of this.contributors) {
|
|
267
|
+
const plan: DyNTS_PrivacyContributorPlan_Interface | undefined = plans.find((
|
|
268
|
+
item: DyNTS_PrivacyContributorPlan_Interface
|
|
269
|
+
): boolean => item.contributorId === contributor.contributorId);
|
|
270
|
+
const outcome: DyNTS_PrivacyContributorOutcome_Interface | undefined = existing.find((
|
|
271
|
+
item: DyNTS_PrivacyContributorOutcome_Interface
|
|
272
|
+
): boolean => item.contributorId === contributor.contributorId);
|
|
273
|
+
|
|
274
|
+
if (plan && outcome && this.isValidCompletedOutcome(contributor, plan, outcome)) {
|
|
275
|
+
completedContributorIds.add(contributor.contributorId);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
for (const contributor of this.contributors) {
|
|
280
|
+
if (completedContributorIds.has(contributor.contributorId)) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const plan: DyNTS_PrivacyContributorPlan_Interface | undefined = plans.find((
|
|
285
|
+
item: DyNTS_PrivacyContributorPlan_Interface
|
|
286
|
+
): boolean => item.contributorId === contributor.contributorId);
|
|
287
|
+
const outcome: DyNTS_PrivacyContributorOutcome_Interface = plan
|
|
288
|
+
? await this.executeContributor(contributor, context, plan)
|
|
289
|
+
: this.buildFailedOutcome(
|
|
290
|
+
contributor.contributorId,
|
|
291
|
+
DyNTS_PrivacyContributorAction_Type.noData,
|
|
292
|
+
'CONTRIBUTOR_PLAN_MISSING'
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
await this.adapter.saveContributorOutcome(requestId, outcome);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private async executeContributor(
|
|
300
|
+
contributor: DyNTS_PrivacyContributor_Interface,
|
|
301
|
+
context: DyNTS_PrivacyContributorContext_Interface,
|
|
302
|
+
plan: DyNTS_PrivacyContributorPlan_Interface
|
|
303
|
+
): Promise<DyNTS_PrivacyContributorOutcome_Interface> {
|
|
304
|
+
try {
|
|
305
|
+
const outcome: DyNTS_PrivacyContributorOutcome_Interface = await contributor.execute(context, plan);
|
|
306
|
+
|
|
307
|
+
this.validateOutcome(contributor, plan, outcome);
|
|
308
|
+
|
|
309
|
+
return { ...outcome };
|
|
310
|
+
} catch (error: unknown) {
|
|
311
|
+
return this.buildFailedOutcome(
|
|
312
|
+
contributor.contributorId,
|
|
313
|
+
plan.action,
|
|
314
|
+
error instanceof DyFM_Error ? 'CONTRIBUTOR_CONTRACT_FAILED' : 'CONTRIBUTOR_EXECUTION_FAILED'
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private async verifyContributorOutcomes(
|
|
320
|
+
context: DyNTS_PrivacyContributorContext_Interface,
|
|
321
|
+
plans: DyNTS_PrivacyContributorPlan_Interface[],
|
|
322
|
+
outcomes: DyNTS_PrivacyContributorOutcome_Interface[]
|
|
323
|
+
): Promise<void> {
|
|
324
|
+
for (const contributor of this.contributors) {
|
|
325
|
+
const outcome: DyNTS_PrivacyContributorOutcome_Interface | undefined = outcomes.find((
|
|
326
|
+
item: DyNTS_PrivacyContributorOutcome_Interface
|
|
327
|
+
): boolean => item.contributorId === contributor.contributorId);
|
|
328
|
+
const plan: DyNTS_PrivacyContributorPlan_Interface | undefined = plans.find((
|
|
329
|
+
item: DyNTS_PrivacyContributorPlan_Interface
|
|
330
|
+
): boolean => item.contributorId === contributor.contributorId);
|
|
331
|
+
|
|
332
|
+
if (!outcome || outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.failed || !plan) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
this.validateOutcome(contributor, plan, outcome);
|
|
338
|
+
|
|
339
|
+
if (!await contributor.verify(context, outcome)) {
|
|
340
|
+
await this.adapter.saveContributorOutcome(context.requestId, this.buildFailedOutcome(
|
|
341
|
+
contributor.contributorId,
|
|
342
|
+
outcome.action,
|
|
343
|
+
'CONTRIBUTOR_VERIFY_FAILED'
|
|
344
|
+
));
|
|
345
|
+
}
|
|
346
|
+
} catch {
|
|
347
|
+
await this.adapter.saveContributorOutcome(context.requestId, this.buildFailedOutcome(
|
|
348
|
+
contributor.contributorId,
|
|
349
|
+
outcome.action,
|
|
350
|
+
'CONTRIBUTOR_VERIFY_FAILED'
|
|
351
|
+
));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
private validatePlan(
|
|
357
|
+
contributor: DyNTS_PrivacyContributor_Interface,
|
|
358
|
+
plan: DyNTS_PrivacyContributorPlan_Interface
|
|
359
|
+
): void {
|
|
360
|
+
if (
|
|
361
|
+
plan.contributorId !== contributor.contributorId
|
|
362
|
+
|| !this.isBoundedText(plan.contributorId, 128)
|
|
363
|
+
|| !Object.values(DyNTS_PrivacyContributorAction_Type).includes(plan.action)
|
|
364
|
+
|| (plan.action === DyNTS_PrivacyContributorAction_Type.retainWithBasis && !plan.retentionBasisCode)
|
|
365
|
+
|| (plan.action !== DyNTS_PrivacyContributorAction_Type.retainWithBasis && !!plan.retentionBasisCode)
|
|
366
|
+
) {
|
|
367
|
+
throw this.buildError(500, 'CONTRIBUTOR_PLAN_INVALID', 'A privacy contributor returned an invalid plan.');
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private validateOutcome(
|
|
372
|
+
contributor: DyNTS_PrivacyContributor_Interface,
|
|
373
|
+
plan: DyNTS_PrivacyContributorPlan_Interface,
|
|
374
|
+
outcome: DyNTS_PrivacyContributorOutcome_Interface
|
|
375
|
+
): void {
|
|
376
|
+
if (
|
|
377
|
+
outcome.contributorId !== contributor.contributorId
|
|
378
|
+
|| outcome.action !== plan.action
|
|
379
|
+
|| !Object.values(DyNTS_PrivacyContributorOutcome_Type).includes(outcome.outcome)
|
|
380
|
+
|| !Number.isSafeInteger(outcome.processedRecordCount)
|
|
381
|
+
|| outcome.processedRecordCount < 0
|
|
382
|
+
|| (outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis
|
|
383
|
+
&& outcome.retentionBasisCode !== plan.retentionBasisCode)
|
|
384
|
+
|| (outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis
|
|
385
|
+
&& !!outcome.retentionBasisCode)
|
|
386
|
+
|| (outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.failed && !outcome.errorCode)
|
|
387
|
+
|| (outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed && !!outcome.errorCode)
|
|
388
|
+
|| (outcome.action === DyNTS_PrivacyContributorAction_Type.retainWithBasis
|
|
389
|
+
&& outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis
|
|
390
|
+
&& outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed)
|
|
391
|
+
|| (outcome.action !== DyNTS_PrivacyContributorAction_Type.retainWithBasis
|
|
392
|
+
&& outcome.outcome === DyNTS_PrivacyContributorOutcome_Type.retainedWithBasis)
|
|
393
|
+
|| (!!outcome.artifactChecksum && !/^[a-f0-9]{64}$/u.test(outcome.artifactChecksum))
|
|
394
|
+
|| !Number.isFinite(new Date(outcome.completedAt).getTime())
|
|
395
|
+
) {
|
|
396
|
+
throw this.buildError(500, 'CONTRIBUTOR_OUTCOME_INVALID', 'A privacy contributor returned an invalid outcome.');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private buildFailedOutcome(
|
|
401
|
+
contributorId: string,
|
|
402
|
+
action: DyNTS_PrivacyContributorAction_Type,
|
|
403
|
+
errorCode: string
|
|
404
|
+
): DyNTS_PrivacyContributorOutcome_Interface {
|
|
405
|
+
return {
|
|
406
|
+
contributorId: contributorId,
|
|
407
|
+
action: action,
|
|
408
|
+
outcome: DyNTS_PrivacyContributorOutcome_Type.failed,
|
|
409
|
+
retentionBasisCode: '',
|
|
410
|
+
artifactChecksum: '',
|
|
411
|
+
processedRecordCount: 0,
|
|
412
|
+
errorCode: errorCode,
|
|
413
|
+
completedAt: this.clock().toISOString(),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private async requireOwnedRequest(
|
|
418
|
+
requestId: string,
|
|
419
|
+
subjectId: string
|
|
420
|
+
): Promise<DyNTS_PrivacyRequestRecord_Interface> {
|
|
421
|
+
const request: DyNTS_PrivacyRequestRecord_Interface | null = await this.adapter.findRequestById(requestId);
|
|
422
|
+
|
|
423
|
+
if (request?.subjectId !== subjectId) {
|
|
424
|
+
throw this.buildError(404, 'REQUEST_NOT_FOUND', 'The privacy request was not found.');
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return request;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
private async replaceState(
|
|
431
|
+
request: DyNTS_PrivacyRequestRecord_Interface,
|
|
432
|
+
state: DyNTS_PrivacyRequestState_Type,
|
|
433
|
+
dates: {
|
|
434
|
+
identityVerifiedAt?: string;
|
|
435
|
+
scopedAt?: string;
|
|
436
|
+
plannedAt?: string;
|
|
437
|
+
executionStartedAt?: string;
|
|
438
|
+
verifyingStartedAt?: string;
|
|
439
|
+
completedAt?: string;
|
|
440
|
+
}
|
|
441
|
+
): Promise<DyNTS_PrivacyRequestRecord_Interface> {
|
|
442
|
+
const replacement: DyNTS_PrivacyRequestRecord_Interface = {
|
|
443
|
+
...request,
|
|
444
|
+
...dates,
|
|
445
|
+
state: state,
|
|
446
|
+
revision: request.revision + 1,
|
|
447
|
+
};
|
|
448
|
+
const didReplace: boolean = await this.adapter.replaceRequest(replacement, request.revision);
|
|
449
|
+
|
|
450
|
+
if (!didReplace) {
|
|
451
|
+
throw this.buildError(409, 'REQUEST_REVISION_CONFLICT', 'The privacy request changed concurrently.');
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return replacement;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
private buildContext(request: DyNTS_PrivacyRequestRecord_Interface): DyNTS_PrivacyContributorContext_Interface {
|
|
458
|
+
return {
|
|
459
|
+
requestId: request.requestId,
|
|
460
|
+
subjectId: request.subjectId,
|
|
461
|
+
organizationId: request.organizationId,
|
|
462
|
+
type: request.type,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
private buildResult(
|
|
467
|
+
request: DyNTS_PrivacyRequestRecord_Interface,
|
|
468
|
+
outcomes: DyNTS_PrivacyContributorOutcome_Interface[]
|
|
469
|
+
): DyNTS_PrivacyRequestResult_Interface {
|
|
470
|
+
if (outcomes.some((outcome: DyNTS_PrivacyContributorOutcome_Interface): boolean => (
|
|
471
|
+
!this.contributors.some((contributor: DyNTS_PrivacyContributor_Interface): boolean => (
|
|
472
|
+
contributor.contributorId === outcome.contributorId
|
|
473
|
+
))
|
|
474
|
+
))) {
|
|
475
|
+
throw this.buildError(500, 'CONTRIBUTOR_OUTCOME_UNKNOWN', 'An unknown contributor outcome was stored.');
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return {
|
|
479
|
+
request: this.toRequestView(request),
|
|
480
|
+
outcomes: [ ...outcomes ].sort((
|
|
481
|
+
first: DyNTS_PrivacyContributorOutcome_Interface,
|
|
482
|
+
second: DyNTS_PrivacyContributorOutcome_Interface
|
|
483
|
+
): number => (
|
|
484
|
+
first.contributorId.localeCompare(second.contributorId)
|
|
485
|
+
)),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
private toRequestView(request: DyNTS_PrivacyRequestRecord_Interface): DyNTS_PrivacyRequestView_Interface {
|
|
490
|
+
return {
|
|
491
|
+
requestId: request.requestId,
|
|
492
|
+
subjectId: request.subjectId,
|
|
493
|
+
organizationId: request.organizationId,
|
|
494
|
+
type: request.type,
|
|
495
|
+
state: request.state,
|
|
496
|
+
revision: request.revision,
|
|
497
|
+
createdAt: request.createdAt,
|
|
498
|
+
deadlineAt: request.deadlineAt,
|
|
499
|
+
identityVerifiedAt: request.identityVerifiedAt,
|
|
500
|
+
scopedAt: request.scopedAt,
|
|
501
|
+
plannedAt: request.plannedAt,
|
|
502
|
+
executionStartedAt: request.executionStartedAt,
|
|
503
|
+
verifyingStartedAt: request.verifyingStartedAt,
|
|
504
|
+
completedAt: request.completedAt,
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
private hashIdempotency(set: DyNTS_PrivacyRequestOpen_Interface): string {
|
|
509
|
+
return createHash('sha256')
|
|
510
|
+
.update(`${set.subjectId}\u0000${set.organizationId}\u0000${set.type}\u0000${set.idempotencyKey}`)
|
|
511
|
+
.digest('hex');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
private isFutureDate(value: string): boolean {
|
|
515
|
+
const timestamp: number = new Date(value).getTime();
|
|
516
|
+
|
|
517
|
+
return Number.isFinite(timestamp) && timestamp > this.clock().getTime();
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private isBoundedText(value: string, maxLength: number): boolean {
|
|
521
|
+
return typeof value === 'string' && !!value && value.length <= maxLength && !value.includes('\u0000');
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
private hasAllContributorPlans(plans: DyNTS_PrivacyContributorPlan_Interface[]): boolean {
|
|
525
|
+
return this.contributors.every((contributor: DyNTS_PrivacyContributor_Interface): boolean => (
|
|
526
|
+
plans.some((plan: DyNTS_PrivacyContributorPlan_Interface): boolean => (
|
|
527
|
+
plan.contributorId === contributor.contributorId
|
|
528
|
+
))
|
|
529
|
+
));
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
private validateStoredPlans(plans: DyNTS_PrivacyContributorPlan_Interface[]): void {
|
|
533
|
+
for (const plan of plans) {
|
|
534
|
+
const contributor: DyNTS_PrivacyContributor_Interface | undefined = this.contributors.find((
|
|
535
|
+
item: DyNTS_PrivacyContributor_Interface
|
|
536
|
+
): boolean => item.contributorId === plan.contributorId);
|
|
537
|
+
|
|
538
|
+
if (!contributor) {
|
|
539
|
+
throw this.buildError(500, 'CONTRIBUTOR_PLAN_UNKNOWN', 'An unknown privacy contributor plan was stored.');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
this.validatePlan(contributor, plan);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
private isValidCompletedOutcome(
|
|
547
|
+
contributor: DyNTS_PrivacyContributor_Interface,
|
|
548
|
+
plan: DyNTS_PrivacyContributorPlan_Interface,
|
|
549
|
+
outcome: DyNTS_PrivacyContributorOutcome_Interface
|
|
550
|
+
): boolean {
|
|
551
|
+
try {
|
|
552
|
+
this.validateOutcome(contributor, plan, outcome);
|
|
553
|
+
|
|
554
|
+
return outcome.outcome !== DyNTS_PrivacyContributorOutcome_Type.failed;
|
|
555
|
+
} catch {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
private validateSettings(): void {
|
|
561
|
+
const contributorIds: string[] = this.contributors.map((item: DyNTS_PrivacyContributor_Interface): string => (
|
|
562
|
+
item.contributorId
|
|
563
|
+
));
|
|
564
|
+
|
|
565
|
+
if (
|
|
566
|
+
!this.adapter
|
|
567
|
+
|| !this.contributors.length
|
|
568
|
+
|| contributorIds.some((contributorId: string): boolean => !contributorId)
|
|
569
|
+
|| new Set(contributorIds).size !== contributorIds.length
|
|
570
|
+
) {
|
|
571
|
+
throw this.buildError(500, 'SETTINGS_INVALID', 'The privacy lifecycle settings are invalid.');
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
private buildError(status: number, errorCode: string, message: string): DyFM_Error {
|
|
576
|
+
return new DyFM_Error({
|
|
577
|
+
status: status,
|
|
578
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|PRIVACY_LIFECYCLE|${errorCode}`,
|
|
579
|
+
message: message,
|
|
580
|
+
userMessage: status < 500
|
|
581
|
+
? message
|
|
582
|
+
: 'The privacy request could not be processed safely. Please try again later.',
|
|
583
|
+
issuerService: this.constructor.name,
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|