@bett3r-dev/pv3 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adapters/cache/index.d.ts +2 -0
- package/build/adapters/cache/index.d.ts.map +1 -0
- package/build/adapters/cache/index.js +18 -0
- package/build/adapters/cache/index.js.map +1 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.d.ts +1 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.d.ts.map +1 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.js +6 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.js.map +1 -0
- package/build/adapters/cache/memory/index.d.ts +3 -0
- package/build/adapters/cache/memory/index.d.ts.map +1 -0
- package/build/adapters/cache/memory/index.js +119 -0
- package/build/adapters/cache/memory/index.js.map +1 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.d.ts +2 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.d.ts.map +1 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.js +43 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.js.map +1 -0
- package/build/adapters/configuration/dotEnv.d.ts +3 -0
- package/build/adapters/configuration/dotEnv.d.ts.map +1 -0
- package/build/adapters/configuration/dotEnv.js +35 -0
- package/build/adapters/configuration/dotEnv.js.map +1 -0
- package/build/adapters/configuration/index.d.ts +2 -0
- package/build/adapters/configuration/index.d.ts.map +1 -0
- package/build/adapters/configuration/index.js +18 -0
- package/build/adapters/configuration/index.js.map +1 -0
- package/build/adapters/database/index.d.ts +2 -0
- package/build/adapters/database/index.d.ts.map +1 -0
- package/build/adapters/database/index.js +18 -0
- package/build/adapters/database/index.js.map +1 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.d.ts +1 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.d.ts.map +1 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.js +36 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.js.map +1 -0
- package/build/adapters/database/memory/index.d.ts +3 -0
- package/build/adapters/database/memory/index.d.ts.map +1 -0
- package/build/adapters/database/memory/index.js +241 -0
- package/build/adapters/database/memory/index.js.map +1 -0
- package/build/adapters/endpoints/addAuthUser/index.d.ts +8 -0
- package/build/adapters/endpoints/addAuthUser/index.d.ts.map +1 -0
- package/build/adapters/endpoints/addAuthUser/index.js +57 -0
- package/build/adapters/endpoints/addAuthUser/index.js.map +1 -0
- package/build/adapters/endpoints/endpointValidation/index.d.ts +4 -0
- package/build/adapters/endpoints/endpointValidation/index.d.ts.map +1 -0
- package/build/adapters/endpoints/endpointValidation/index.js +27 -0
- package/build/adapters/endpoints/endpointValidation/index.js.map +1 -0
- package/build/adapters/endpoints/index.d.ts +4 -0
- package/build/adapters/endpoints/index.d.ts.map +1 -0
- package/build/adapters/endpoints/index.js +21 -0
- package/build/adapters/endpoints/index.js.map +1 -0
- package/build/adapters/endpoints/localAuthorization/index.d.ts +1 -0
- package/build/adapters/endpoints/localAuthorization/index.d.ts.map +1 -0
- package/build/adapters/endpoints/localAuthorization/index.js +68 -0
- package/build/adapters/endpoints/localAuthorization/index.js.map +1 -0
- package/build/adapters/endpoints/tcpConsumer/index.d.ts +3 -0
- package/build/adapters/endpoints/tcpConsumer/index.d.ts.map +1 -0
- package/build/adapters/endpoints/tcpConsumer/index.js +64 -0
- package/build/adapters/endpoints/tcpConsumer/index.js.map +1 -0
- package/build/adapters/endpoints/userSession/index.d.ts +8 -0
- package/build/adapters/endpoints/userSession/index.d.ts.map +1 -0
- package/build/adapters/endpoints/userSession/index.js +43 -0
- package/build/adapters/endpoints/userSession/index.js.map +1 -0
- package/build/adapters/eventstore/database.d.ts +3 -0
- package/build/adapters/eventstore/database.d.ts.map +1 -0
- package/build/adapters/eventstore/database.js +156 -0
- package/build/adapters/eventstore/database.js.map +1 -0
- package/build/adapters/eventstore/index.d.ts +2 -0
- package/build/adapters/eventstore/index.d.ts.map +1 -0
- package/build/adapters/eventstore/index.js +18 -0
- package/build/adapters/eventstore/index.js.map +1 -0
- package/build/adapters/infrastructure/index.d.ts +2 -0
- package/build/adapters/infrastructure/index.d.ts.map +1 -0
- package/build/adapters/infrastructure/index.js +18 -0
- package/build/adapters/infrastructure/index.js.map +1 -0
- package/build/adapters/infrastructure/local/index.d.ts +4 -0
- package/build/adapters/infrastructure/local/index.d.ts.map +1 -0
- package/build/adapters/infrastructure/local/index.js +37 -0
- package/build/adapters/infrastructure/local/index.js.map +1 -0
- package/build/adapters/logger/console.d.ts +3 -0
- package/build/adapters/logger/console.d.ts.map +1 -0
- package/build/adapters/logger/console.js +38 -0
- package/build/adapters/logger/console.js.map +1 -0
- package/build/adapters/logger/index.d.ts +2 -0
- package/build/adapters/logger/index.d.ts.map +1 -0
- package/build/adapters/logger/index.js +18 -0
- package/build/adapters/logger/index.js.map +1 -0
- package/build/index.d.ts +23 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +39 -0
- package/build/index.js.map +1 -0
- package/build/libraries/modules/fs.d.ts +12 -0
- package/build/libraries/modules/fs.d.ts.map +1 -0
- package/build/libraries/modules/fs.js +103 -0
- package/build/libraries/modules/fs.js.map +1 -0
- package/build/libraries/modules/index.d.ts +2 -0
- package/build/libraries/modules/index.d.ts.map +1 -0
- package/build/libraries/modules/index.js +18 -0
- package/build/libraries/modules/index.js.map +1 -0
- package/build/libraries/openApi/index.d.ts +2 -0
- package/build/libraries/openApi/index.d.ts.map +1 -0
- package/build/libraries/openApi/index.js +18 -0
- package/build/libraries/openApi/index.js.map +1 -0
- package/build/libraries/openApi/pruneUnusedRef.d.ts +3 -0
- package/build/libraries/openApi/pruneUnusedRef.d.ts.map +1 -0
- package/build/libraries/openApi/pruneUnusedRef.js +30 -0
- package/build/libraries/openApi/pruneUnusedRef.js.map +1 -0
- package/build/libraries/tcp/index.d.ts +8 -0
- package/build/libraries/tcp/index.d.ts.map +1 -0
- package/build/libraries/tcp/index.js +108 -0
- package/build/libraries/tcp/index.js.map +1 -0
- package/build/libraries/tcp/types.d.ts +45 -0
- package/build/libraries/tcp/types.d.ts.map +1 -0
- package/build/libraries/tcp/types.js +3 -0
- package/build/libraries/tcp/types.js.map +1 -0
- package/build/libraries/validation/__tests__/validation.test.d.ts +2 -0
- package/build/libraries/validation/__tests__/validation.test.d.ts.map +1 -0
- package/build/libraries/validation/__tests__/validation.test.js +53 -0
- package/build/libraries/validation/__tests__/validation.test.js.map +1 -0
- package/build/libraries/validation/index.d.ts +8 -0
- package/build/libraries/validation/index.d.ts.map +1 -0
- package/build/libraries/validation/index.js +51 -0
- package/build/libraries/validation/index.js.map +1 -0
- package/build/ports/authentication/index.d.ts +12 -0
- package/build/ports/authentication/index.d.ts.map +1 -0
- package/build/ports/authentication/index.js +23 -0
- package/build/ports/authentication/index.js.map +1 -0
- package/build/ports/base.d.ts +7 -0
- package/build/ports/base.d.ts.map +1 -0
- package/build/ports/base.js +25 -0
- package/build/ports/base.js.map +1 -0
- package/build/ports/cache/index.d.ts +3 -0
- package/build/ports/cache/index.d.ts.map +1 -0
- package/build/ports/cache/index.js +19 -0
- package/build/ports/cache/index.js.map +1 -0
- package/build/ports/configuration/__tests__/configurationPort.test.d.ts +2 -0
- package/build/ports/configuration/__tests__/configurationPort.test.d.ts.map +1 -0
- package/build/ports/configuration/__tests__/configurationPort.test.js +51 -0
- package/build/ports/configuration/__tests__/configurationPort.test.js.map +1 -0
- package/build/ports/configuration/args.d.ts +57 -0
- package/build/ports/configuration/args.d.ts.map +1 -0
- package/build/ports/configuration/args.js +44 -0
- package/build/ports/configuration/args.js.map +1 -0
- package/build/ports/configuration/common.d.ts +2 -0
- package/build/ports/configuration/common.d.ts.map +1 -0
- package/build/ports/configuration/common.js +19 -0
- package/build/ports/configuration/common.js.map +1 -0
- package/build/ports/configuration/index.d.ts +10 -0
- package/build/ports/configuration/index.d.ts.map +1 -0
- package/build/ports/configuration/index.js +96 -0
- package/build/ports/configuration/index.js.map +1 -0
- package/build/ports/configuration/localConfig.d.ts +3 -0
- package/build/ports/configuration/localConfig.d.ts.map +1 -0
- package/build/ports/configuration/localConfig.js +108 -0
- package/build/ports/configuration/localConfig.js.map +1 -0
- package/build/ports/database/index.d.ts +4 -0
- package/build/ports/database/index.d.ts.map +1 -0
- package/build/ports/database/index.js +27 -0
- package/build/ports/database/index.js.map +1 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.d.ts +2 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.js +21 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.js.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.d.ts +77 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.js +91 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.js.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.d.ts +29 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.js +43 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.js.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.d.ts +106 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.js +62 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.js.map +1 -0
- package/build/ports/endpoints/__tests__/utils.test.d.ts +1 -0
- package/build/ports/endpoints/__tests__/utils.test.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/utils.test.js +53 -0
- package/build/ports/endpoints/__tests__/utils.test.js.map +1 -0
- package/build/ports/endpoints/index.d.ts +29 -0
- package/build/ports/endpoints/index.d.ts.map +1 -0
- package/build/ports/endpoints/index.js +263 -0
- package/build/ports/endpoints/index.js.map +1 -0
- package/build/ports/endpoints/openApi.d.ts +16 -0
- package/build/ports/endpoints/openApi.d.ts.map +1 -0
- package/build/ports/endpoints/openApi.js +187 -0
- package/build/ports/endpoints/openApi.js.map +1 -0
- package/build/ports/endpoints/utils.d.ts +17 -0
- package/build/ports/endpoints/utils.d.ts.map +1 -0
- package/build/ports/endpoints/utils.js +31 -0
- package/build/ports/endpoints/utils.js.map +1 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.d.ts +2 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.d.ts.map +1 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.js +35 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.js.map +1 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.d.ts +2 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.d.ts.map +1 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.js +210 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.js.map +1 -0
- package/build/ports/eventsourcing/commandHandlers/index.d.ts +25 -0
- package/build/ports/eventsourcing/commandHandlers/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandHandlers/index.js +392 -0
- package/build/ports/eventsourcing/commandHandlers/index.js.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/index.d.ts +3 -0
- package/build/ports/eventsourcing/commandTemplates/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/index.js +19 -0
- package/build/ports/eventsourcing/commandTemplates/index.js.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.d.ts +4 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.js +73 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.js.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.d.ts +9 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.js +39 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.js.map +1 -0
- package/build/ports/eventsourcing/eventHandlers/index.d.ts +33 -0
- package/build/ports/eventsourcing/eventHandlers/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/eventHandlers/index.js +276 -0
- package/build/ports/eventsourcing/eventHandlers/index.js.map +1 -0
- package/build/ports/eventsourcing/index.d.ts +9 -0
- package/build/ports/eventsourcing/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/index.js +101 -0
- package/build/ports/eventsourcing/index.js.map +1 -0
- package/build/ports/eventsourcing/invariants/combinators.d.ts +4 -0
- package/build/ports/eventsourcing/invariants/combinators.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/combinators.js +20 -0
- package/build/ports/eventsourcing/invariants/combinators.js.map +1 -0
- package/build/ports/eventsourcing/invariants/common.d.ts +10 -0
- package/build/ports/eventsourcing/invariants/common.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/common.js +37 -0
- package/build/ports/eventsourcing/invariants/common.js.map +1 -0
- package/build/ports/eventsourcing/invariants/comparisons.d.ts +19 -0
- package/build/ports/eventsourcing/invariants/comparisons.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/comparisons.js +83 -0
- package/build/ports/eventsourcing/invariants/comparisons.js.map +1 -0
- package/build/ports/eventsourcing/invariants/index.d.ts +5 -0
- package/build/ports/eventsourcing/invariants/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/index.js +21 -0
- package/build/ports/eventsourcing/invariants/index.js.map +1 -0
- package/build/ports/eventsourcing/invariants/stateExistance.d.ts +4 -0
- package/build/ports/eventsourcing/invariants/stateExistance.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/stateExistance.js +33 -0
- package/build/ports/eventsourcing/invariants/stateExistance.js.map +1 -0
- package/build/ports/eventsourcing/subscriptions/index.d.ts +2 -0
- package/build/ports/eventsourcing/subscriptions/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/subscriptions/index.js +18 -0
- package/build/ports/eventsourcing/subscriptions/index.js.map +1 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.d.ts +3 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.d.ts.map +1 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.js +81 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.js.map +1 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.d.ts +4 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.js +45 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/commandBuilder.d.ts +3 -0
- package/build/ports/eventsourcing/utils/commandBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/commandBuilder.js +102 -0
- package/build/ports/eventsourcing/utils/commandBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.d.ts +3 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.js +19 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.d.ts +4 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.js +34 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/index.d.ts +13 -0
- package/build/ports/eventsourcing/utils/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/index.js +45 -0
- package/build/ports/eventsourcing/utils/index.js.map +1 -0
- package/build/ports/eventsourcing/utils/policyBuilder.d.ts +3 -0
- package/build/ports/eventsourcing/utils/policyBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/policyBuilder.js +29 -0
- package/build/ports/eventsourcing/utils/policyBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.d.ts +5 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.js +45 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.js.map +1 -0
- package/build/ports/eventstore/index.d.ts +3 -0
- package/build/ports/eventstore/index.d.ts.map +1 -0
- package/build/ports/eventstore/index.js +13 -0
- package/build/ports/eventstore/index.js.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/index.d.ts +3 -0
- package/build/ports/infrastructure/__tests__/fixture/index.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/index.js +19 -0
- package/build/ports/infrastructure/__tests__/fixture/index.js.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.d.ts +19 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.js +76 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.js.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.d.ts +177 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.js +258 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.js.map +1 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.d.ts +2 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.js +11 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.js.map +1 -0
- package/build/ports/infrastructure/index.d.ts +53 -0
- package/build/ports/infrastructure/index.d.ts.map +1 -0
- package/build/ports/infrastructure/index.js +149 -0
- package/build/ports/infrastructure/index.js.map +1 -0
- package/build/ports/infrastructure/utils.d.ts +14 -0
- package/build/ports/infrastructure/utils.d.ts.map +1 -0
- package/build/ports/infrastructure/utils.js +126 -0
- package/build/ports/infrastructure/utils.js.map +1 -0
- package/build/ports/logger/index.d.ts +3 -0
- package/build/ports/logger/index.d.ts.map +1 -0
- package/build/ports/logger/index.js +32 -0
- package/build/ports/logger/index.js.map +1 -0
- package/build/utils/index.d.ts +35 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +190 -0
- package/build/utils/index.js.map +1 -0
- package/package.json +28 -0
- package/src/adapters/cache/index.ts +1 -0
- package/src/adapters/cache/memory/__tests__/memoryCache.test.ts +6 -0
- package/src/adapters/cache/memory/index.ts +142 -0
- package/src/adapters/configuration/__tests__/.env +4 -0
- package/src/adapters/configuration/__tests__/dotEnv.test.ts +38 -0
- package/src/adapters/configuration/dotEnv.ts +33 -0
- package/src/adapters/configuration/index.ts +1 -0
- package/src/adapters/database/index.ts +1 -0
- package/src/adapters/database/memory/__tests__/memoryDb.test.ts +37 -0
- package/src/adapters/database/memory/index.ts +279 -0
- package/src/adapters/endpoints/addAuthUser/index.ts +55 -0
- package/src/adapters/endpoints/endpointValidation/index.ts +26 -0
- package/src/adapters/endpoints/index.ts +4 -0
- package/src/adapters/endpoints/localAuthorization/index.ts +75 -0
- package/src/adapters/endpoints/tcpConsumer/index.ts +69 -0
- package/src/adapters/endpoints/userSession/index.ts +40 -0
- package/src/adapters/eventstore/database.ts +178 -0
- package/src/adapters/eventstore/index.ts +1 -0
- package/src/adapters/infrastructure/index.ts +1 -0
- package/src/adapters/infrastructure/local/index.ts +40 -0
- package/src/adapters/logger/console.ts +42 -0
- package/src/adapters/logger/index.ts +1 -0
- package/src/index.ts +25 -0
- package/src/libraries/modules/fs.ts +88 -0
- package/src/libraries/modules/index.ts +1 -0
- package/src/libraries/openApi/index.ts +1 -0
- package/src/libraries/openApi/pruneUnusedRef.ts +35 -0
- package/src/libraries/tcp/index.ts +98 -0
- package/src/libraries/tcp/types.ts +43 -0
- package/src/libraries/validation/__tests__/validation.test.ts +25 -0
- package/src/libraries/validation/index.ts +48 -0
- package/src/ports/authentication/index.ts +25 -0
- package/src/ports/base.ts +20 -0
- package/src/ports/cache/index.ts +17 -0
- package/src/ports/configuration/__tests__/configurationPort.test.ts +47 -0
- package/src/ports/configuration/args.ts +39 -0
- package/src/ports/configuration/common.ts +12 -0
- package/src/ports/configuration/index.ts +110 -0
- package/src/ports/configuration/localConfig.ts +117 -0
- package/src/ports/database/index.ts +25 -0
- package/src/ports/endpoints/__tests__/endpointsCall.test.ts +20 -0
- package/src/ports/endpoints/__tests__/test-client-library/base.ts +167 -0
- package/src/ports/endpoints/__tests__/test-client-library/index.ts +23 -0
- package/src/ports/endpoints/__tests__/test-client-library/services/service.ts +181 -0
- package/src/ports/endpoints/__tests__/utils.test.ts +54 -0
- package/src/ports/endpoints/index.ts +272 -0
- package/src/ports/endpoints/openApi.ts +191 -0
- package/src/ports/endpoints/utils.ts +31 -0
- package/src/ports/eventsourcing/__tests__/eventhandlers.test.ts +30 -0
- package/src/ports/eventsourcing/__tests__/invariants.test.ts +213 -0
- package/src/ports/eventsourcing/commandHandlers/index.ts +625 -0
- package/src/ports/eventsourcing/commandTemplates/index.ts +2 -0
- package/src/ports/eventsourcing/commandTemplates/multiStream.ts +70 -0
- package/src/ports/eventsourcing/commandTemplates/snapshot.ts +43 -0
- package/src/ports/eventsourcing/eventHandlers/index.ts +429 -0
- package/src/ports/eventsourcing/index.ts +98 -0
- package/src/ports/eventsourcing/invariants/combinators.ts +25 -0
- package/src/ports/eventsourcing/invariants/common.ts +42 -0
- package/src/ports/eventsourcing/invariants/comparisons.ts +90 -0
- package/src/ports/eventsourcing/invariants/index.ts +4 -0
- package/src/ports/eventsourcing/invariants/stateExistance.ts +34 -0
- package/src/ports/eventsourcing/subscriptions/index.ts +1 -0
- package/src/ports/eventsourcing/subscriptions/sseSubscriptions.ts +103 -0
- package/src/ports/eventsourcing/utils/aggregateBuilder.ts +49 -0
- package/src/ports/eventsourcing/utils/commandBuilder.ts +113 -0
- package/src/ports/eventsourcing/utils/eventHandlerBuilder.ts +22 -0
- package/src/ports/eventsourcing/utils/externalSystemBuilder.ts +42 -0
- package/src/ports/eventsourcing/utils/index.ts +25 -0
- package/src/ports/eventsourcing/utils/policyBuilder.ts +31 -0
- package/src/ports/eventsourcing/utils/readmodelBuilder.ts +52 -0
- package/src/ports/eventstore/index.ts +11 -0
- package/src/ports/infrastructure/__tests__/fixture/index.ts +2 -0
- package/src/ports/infrastructure/__tests__/fixture/infrastructureServices.ts +72 -0
- package/src/ports/infrastructure/__tests__/fixture/structureState.ts +254 -0
- package/src/ports/infrastructure/__tests__/infrastructure.test.ts +11 -0
- package/src/ports/infrastructure/index.ts +162 -0
- package/src/ports/infrastructure/utils.ts +130 -0
- package/src/ports/logger/index.ts +34 -0
- package/src/utils/index.ts +186 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { ensureArray, TypedEventEmitter } from '@bett3r-dev/bett3r-utils';
|
|
2
|
+
import { Collection, CollectionFilter, CollectionFilterInstance, CollectionOperations, CollectionQueryParams, DatabaseAdapter, DatabaseChange, Document, filterOpMap, IndexOptions } from '@bett3r-dev/pv3-types';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { assocPath, clone, path, pick, props } from 'ramda';
|
|
5
|
+
import { DuplicatedValueInIndex } from '../../../ports/database';
|
|
6
|
+
import { createError } from '../../../utils';
|
|
7
|
+
|
|
8
|
+
export const MemoryDb = (): DatabaseAdapter => {
|
|
9
|
+
let _db = {};
|
|
10
|
+
const changeEmitters: Record<string, TypedEventEmitter<{'change': DatabaseChange}>> = {};
|
|
11
|
+
type UniqueIndexes = {
|
|
12
|
+
[collection: string]:{
|
|
13
|
+
[index: string] : string[]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const uniqueIndexes: UniqueIndexes = {};
|
|
18
|
+
|
|
19
|
+
const start = async () => {
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const stop = async () => {
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const getCollection = <Model extends Document>( collection:string ): Collection<Model> => {
|
|
27
|
+
const coll = _db[collection] ||= {};
|
|
28
|
+
|
|
29
|
+
const validateIndex = ( data: any ) => {
|
|
30
|
+
if ( !uniqueIndexes[collection]) return;
|
|
31
|
+
const duplicatedIndex = Object.keys( uniqueIndexes[collection]).find( index => {
|
|
32
|
+
const properties = uniqueIndexes[collection][index];
|
|
33
|
+
const recordComparison = Object.values( coll ).find(( d: any )=> {
|
|
34
|
+
const valueComparison = properties.every( p =>{
|
|
35
|
+
return path( p.split( '.' ), d ) === path( p.split( '.' ), data );
|
|
36
|
+
});
|
|
37
|
+
return valueComparison;
|
|
38
|
+
});
|
|
39
|
+
return recordComparison;
|
|
40
|
+
});
|
|
41
|
+
return duplicatedIndex && {
|
|
42
|
+
index: duplicatedIndex,
|
|
43
|
+
properties: uniqueIndexes[collection][duplicatedIndex]
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const readById = async ( id: string|number ): Promise<Model | null> => {
|
|
48
|
+
return coll[id] || null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const filterData = ( results: any[], filter: CollectionFilter<Model>[]) => {
|
|
52
|
+
const shouldFilter = ( row: any, filter: CollectionFilter<Model>[]) => filter.every( f=> {
|
|
53
|
+
if ( f.AND ){
|
|
54
|
+
return f.AND.every( andFilters=> shouldFilter( row, [andFilters]));
|
|
55
|
+
}
|
|
56
|
+
if ( f.OR ){
|
|
57
|
+
return f.OR.some( orFilters=> shouldFilter( row, [orFilters]));
|
|
58
|
+
}
|
|
59
|
+
return filterOpMap[( f as any ).op]( path([f.field as string], row ), f.value );
|
|
60
|
+
});
|
|
61
|
+
return results.filter( row => shouldFilter( row, filter ));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const hashId = ( id: string|number ) => {
|
|
65
|
+
let intId = Number( id );
|
|
66
|
+
if ( !isNaN( intId )) return intId;
|
|
67
|
+
const factor = 2;
|
|
68
|
+
let hash = 0;
|
|
69
|
+
for ( let i = 0; i < ( id as string ).length; i++ ) {
|
|
70
|
+
hash = hash * factor + ( id as string ).charCodeAt( i );
|
|
71
|
+
}
|
|
72
|
+
return Math.abs( hash );
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const query = async (
|
|
76
|
+
queryParams: CollectionQueryParams<Model>
|
|
77
|
+
): Promise<Model[]> => {
|
|
78
|
+
const { limit, filter, sort, after, select } = queryParams;
|
|
79
|
+
let result = Object.values( coll );
|
|
80
|
+
|
|
81
|
+
if ( after ){
|
|
82
|
+
const sortedKeys = Object.keys( coll ).map(( key ) => [ key, hashId( key ) ])
|
|
83
|
+
.sort(( a:any, b:any ) => a[1] - b[1])
|
|
84
|
+
.map(( a:any ) => a[0]);
|
|
85
|
+
const index = sortedKeys.indexOf( after.toString());
|
|
86
|
+
result = props( sortedKeys.slice( index + 1 ), coll );
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
result = !filter ? result : filterData( result, filter );
|
|
90
|
+
|
|
91
|
+
result = !sort ? result : sort
|
|
92
|
+
.reduce(( result, sort ) => {
|
|
93
|
+
return result.sort(( a: any, b: any ) => {
|
|
94
|
+
return sort.direction === 'desc'
|
|
95
|
+
? ( a[sort.field] < b[sort.field] ? 1 : -1 )
|
|
96
|
+
: ( a[sort.field] >= b[sort.field] ? 1 : -1 );
|
|
97
|
+
});
|
|
98
|
+
}, result );
|
|
99
|
+
|
|
100
|
+
result = !limit ? result : result.slice( 0, limit );
|
|
101
|
+
|
|
102
|
+
result = !select ? result : result.map( pick( ensureArray( select as string )));
|
|
103
|
+
|
|
104
|
+
return result as Model[];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const forEach = async (
|
|
108
|
+
queryParams: CollectionQueryParams<Model>,
|
|
109
|
+
callback: ( record: Model, stop: () => void ) => void | Promise<void>
|
|
110
|
+
): Promise<void> => {
|
|
111
|
+
let shouldStop = false;
|
|
112
|
+
const stop = () => {
|
|
113
|
+
shouldStop = true;
|
|
114
|
+
};
|
|
115
|
+
await query( queryParams )
|
|
116
|
+
.then( async records =>{
|
|
117
|
+
for ( let index = 0; index < records.length; index++ ) {
|
|
118
|
+
const element = records[index];
|
|
119
|
+
if ( shouldStop ) return;
|
|
120
|
+
await callback( element, stop );
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const upsert = async (
|
|
126
|
+
id: string|number,
|
|
127
|
+
data: Partial<Model>
|
|
128
|
+
): Promise<Model> => {
|
|
129
|
+
const _data = clone( data );
|
|
130
|
+
const changeType = coll[id] ? 'update' : 'insert';
|
|
131
|
+
if ( changeType === 'insert' ){
|
|
132
|
+
const index = validateIndex( _data );
|
|
133
|
+
if ( index ) return Promise.reject( createError( DuplicatedValueInIndex(), {
|
|
134
|
+
details: index.properties.reduce(( details, p ) => {
|
|
135
|
+
details[p] = path( p.split( '.' ), _data );
|
|
136
|
+
return details;
|
|
137
|
+
}, {})
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
const previous = clone( coll[id]);
|
|
141
|
+
const formatedData = Object.keys( _data ).reduce(( response, key ) => {
|
|
142
|
+
return assocPath( key.split( '.' ), _data[key], response );
|
|
143
|
+
}, clone( coll[id]) || {});
|
|
144
|
+
|
|
145
|
+
coll[id] = { ...formatedData, id };
|
|
146
|
+
changeEmitters[collection]?.emit( 'change', { changeType, data: coll[id], previous });
|
|
147
|
+
return coll[id] as Model;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const destroyById = async ( id: string|number ) =>{
|
|
151
|
+
const previous = coll[id];
|
|
152
|
+
changeEmitters[collection]?.emit( 'change', { changeType: 'delete', previous });
|
|
153
|
+
delete coll[id];
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const createMany = async ( documents: Model[]): Promise<Model[]> => {
|
|
157
|
+
return documents.map( data=>{
|
|
158
|
+
const _data = clone( data );
|
|
159
|
+
validateIndex( _data );
|
|
160
|
+
coll[_data.id] = _data;
|
|
161
|
+
changeEmitters[collection]?.emit( 'change', { changeType: 'insert', data: _data });
|
|
162
|
+
return _data as Model;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const updateMany = async ( filter: CollectionFilterInstance<Model>[], data: Partial<Model> ) => {
|
|
167
|
+
return Object.keys( coll )
|
|
168
|
+
.reduce(( response, rowId ) => {
|
|
169
|
+
if ( filter.every( f=> filterOpMap[( f as any ).op]( path([f.field], coll[rowId]), f.value ))){
|
|
170
|
+
const previous = coll[rowId];
|
|
171
|
+
coll[rowId] = { ...coll[rowId], ...clone( data ) };
|
|
172
|
+
changeEmitters[collection]?.emit( 'change', { changeType: 'update', previous, data: coll[rowId] });
|
|
173
|
+
response.push( coll[rowId]);
|
|
174
|
+
}
|
|
175
|
+
return response;
|
|
176
|
+
}, [] as any[]) as Model[];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const destroyMany = async ( filter: CollectionFilterInstance<Model>[]) => {
|
|
180
|
+
return Object.keys( coll )
|
|
181
|
+
.reduce(( response, rowId ) => {
|
|
182
|
+
if ( filter.every( f=> filterOpMap[( f as any ).op]( path([f.field], coll[rowId]), f.value ))){
|
|
183
|
+
const previous = coll[rowId];
|
|
184
|
+
delete coll[rowId];
|
|
185
|
+
changeEmitters[collection]?.emit( 'change', { changeType: 'delete', previous });
|
|
186
|
+
response.push( rowId );
|
|
187
|
+
}
|
|
188
|
+
return response;
|
|
189
|
+
}, [] as any[])
|
|
190
|
+
.length;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const atomicIncrement = async ( name: string, filter: CollectionFilterInstance<Model>, amount = 1 ): Promise<number> => {
|
|
194
|
+
const fnMap = filterOpMap[( filter as any ).op];
|
|
195
|
+
const key = Object.keys( coll ).find( id => fnMap( path([filter.field], coll[id]), filter.value ));
|
|
196
|
+
if ( !key ){
|
|
197
|
+
const id = randomUUID();
|
|
198
|
+
coll[id] = {
|
|
199
|
+
[filter.field]: filter.value,
|
|
200
|
+
[name]: amount
|
|
201
|
+
};
|
|
202
|
+
changeEmitters[collection]?.emit( 'change', { changeType: 'insert', data: coll[id] });
|
|
203
|
+
return amount;
|
|
204
|
+
} else {
|
|
205
|
+
const previous = coll[key];
|
|
206
|
+
coll[key][name] = ( coll[key][name] || 0 ) + amount;
|
|
207
|
+
changeEmitters[collection]?.emit( 'change', { changeType: 'update', data: coll[key], previous });
|
|
208
|
+
return coll[key][name];
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const ensureIndex = async ( properties: string[], options: IndexOptions = {} as IndexOptions ) =>{
|
|
213
|
+
if ( options.isUnique === true ){
|
|
214
|
+
uniqueIndexes[collection] ||= {};
|
|
215
|
+
uniqueIndexes[collection][properties.join( '_' )] = properties;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const destroyIndex = async ( properties: string[]) =>{
|
|
220
|
+
if ( uniqueIndexes[collection] && uniqueIndexes[collection][properties.join( '_' )]){
|
|
221
|
+
delete uniqueIndexes[collection][properties.join( '_' )];
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const watch = ( changeTypes: ( 'insert'|'update'|'delete' )[] = ['insert'], onData:( data: DatabaseChange<Model> )=>void, onError: ( e: Error ) => void ) => {
|
|
226
|
+
changeEmitters[collection] ||= new TypedEventEmitter<{'change': DatabaseChange}>();
|
|
227
|
+
|
|
228
|
+
const callback = ( change ) => {
|
|
229
|
+
if ( changeTypes.includes( change.changeType ))
|
|
230
|
+
onData( change );
|
|
231
|
+
};
|
|
232
|
+
changeEmitters[collection].on( 'change', callback );
|
|
233
|
+
|
|
234
|
+
return Promise.resolve({
|
|
235
|
+
close: () => changeEmitters[collection].off( 'change', callback )
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
readById,
|
|
241
|
+
query,
|
|
242
|
+
upsert,
|
|
243
|
+
forEach,
|
|
244
|
+
destroyById,
|
|
245
|
+
createMany,
|
|
246
|
+
updateMany,
|
|
247
|
+
destroyMany,
|
|
248
|
+
atomicIncrement,
|
|
249
|
+
ensureIndex,
|
|
250
|
+
destroyIndex,
|
|
251
|
+
watch
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const initTransaction = <Result = any>( operations: ( getCollection: <Model extends Document>( collection: string ) => CollectionOperations<Model> ) => Promise<Result | undefined> ): Promise<Result> => {
|
|
256
|
+
let backupDb = clone( _db );
|
|
257
|
+
const commitTransaction = async ( docs?: Result ) =>{
|
|
258
|
+
return docs || null as Result;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const rollbackTransaction = async ( error: Error ) =>{
|
|
262
|
+
_db = backupDb;
|
|
263
|
+
return Promise.reject( error );
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
return operations( getCollection )
|
|
267
|
+
.then( commitTransaction )
|
|
268
|
+
.catch( rollbackTransaction );
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
_adapter: () => _db,
|
|
273
|
+
name: 'memoryDb',
|
|
274
|
+
start,
|
|
275
|
+
stop,
|
|
276
|
+
getCollection,
|
|
277
|
+
initTransaction
|
|
278
|
+
};
|
|
279
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Endpoint, EndpointActionParams, EndpointsAdapter } from '@bett3r-dev/pv3-types';
|
|
2
|
+
import { path } from 'ramda';
|
|
3
|
+
import { AuthenticationError, createError } from '../../..';
|
|
4
|
+
|
|
5
|
+
const propMapper = ( map: Record<string, string>, object: Record<string, any> ) => {
|
|
6
|
+
const result = {};
|
|
7
|
+
Object.keys( map ).forEach( key => {
|
|
8
|
+
result[map[key]] = path( key.split( '.' ), object );
|
|
9
|
+
});
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Adds the user object to the request context
|
|
15
|
+
* @param customTokenAttributes - Object with key as the path to the attribute in the token and value as the name of the attribute in the user object
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export const AddAuthUserToRequest = ( customTokenAttributes: Record<string, string> ): EndpointsAdapter => {
|
|
19
|
+
const addUserToContext = async ( params: EndpointActionParams ): Promise<EndpointActionParams> =>{
|
|
20
|
+
const token: string = params.context?.req?.headers?.authorization as string || params.query?.access_token;
|
|
21
|
+
if ( !token ) return params;
|
|
22
|
+
try{
|
|
23
|
+
const payload = JSON.parse( Buffer.from( token.split( '.' )[1], 'base64' ).toString());
|
|
24
|
+
if ( !params.context )
|
|
25
|
+
params.context = {};
|
|
26
|
+
params.context.token = token.slice( token.lastIndexOf( ' ' ) + 1 );
|
|
27
|
+
params.context.user = propMapper({
|
|
28
|
+
'email': 'email',
|
|
29
|
+
'realm_access.roles': 'roles',
|
|
30
|
+
'app_id': 'id',
|
|
31
|
+
...customTokenAttributes
|
|
32
|
+
}, payload );
|
|
33
|
+
return Promise.resolve( params );
|
|
34
|
+
} catch ( err ) {
|
|
35
|
+
return Promise.reject( createError( AuthenticationError(), { description: 'Invalid Token' }));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const registerEndpoint = ( endpoint: Endpoint ) => {
|
|
40
|
+
const originalAction = endpoint.action;
|
|
41
|
+
endpoint.action = ( params: EndpointActionParams<any, any, any> ) => {
|
|
42
|
+
return addUserToContext( params )
|
|
43
|
+
.then( originalAction );
|
|
44
|
+
};
|
|
45
|
+
return endpoint;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
_adapter: () => {},
|
|
50
|
+
name: 'addAuthUser',
|
|
51
|
+
start: async()=>{},
|
|
52
|
+
stop: async()=>{},
|
|
53
|
+
registerEndpoint
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseSchema } from '@bett3r-dev/jsonschema-definer';
|
|
2
|
+
import { Endpoint, EndpointActionParams, EndpointsAdapter } from '@bett3r-dev/pv3-types';
|
|
3
|
+
import { validateEndpoint } from '../../../libraries/validation';
|
|
4
|
+
|
|
5
|
+
export const EndpointValidation = ( validateSchema: <T>( schema: BaseSchema<T> ) => ( value:T ) => T, onError: ( err:any, endpoint: Endpoint ) => void = () => {}): EndpointsAdapter => {
|
|
6
|
+
const registerEndpoint = ( endpoint: Endpoint ) => {
|
|
7
|
+
if ( endpoint.shouldValidate === false ) return endpoint;
|
|
8
|
+
const originalAction = endpoint.action;
|
|
9
|
+
endpoint.action = ( params: EndpointActionParams ) =>
|
|
10
|
+
validateEndpoint( validateSchema, endpoint.schemas )( params )
|
|
11
|
+
.catch( e => {
|
|
12
|
+
onError( e, endpoint );
|
|
13
|
+
return Promise.reject( e );
|
|
14
|
+
})
|
|
15
|
+
.then( originalAction );
|
|
16
|
+
return endpoint;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
_adapter: () => {},
|
|
21
|
+
name: 'endpointValidation',
|
|
22
|
+
start: async()=>{},
|
|
23
|
+
stop: async()=>{},
|
|
24
|
+
registerEndpoint
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// import S from '@bett3r-dev/jsonschema-definer';
|
|
2
|
+
// import { compose, mergeRight } from 'ramda';
|
|
3
|
+
// import { AuthenticationPort, /* EndpointMarkedAsPublicSchema, EndpointRolesUpsertedSchema, RouteManagerEndpointAuth */ } from '../../../ports/authentication';
|
|
4
|
+
// import { DatabasePort } from '../../../ports/database';
|
|
5
|
+
// import { Endpoint, EndpointActionParams, EndpointsAdapter, EndpointsPort } from '../../../ports/endpoints';
|
|
6
|
+
|
|
7
|
+
// export type LocalAuthorizationType = EndpointsAdapter & {
|
|
8
|
+
// registerRouteManagementEndpoints: ( endpoints: EndpointsPort ) => void;
|
|
9
|
+
// }
|
|
10
|
+
|
|
11
|
+
// /**
|
|
12
|
+
// * Performs a local authorization of the incoming request by validating the JWT and performing RBAC authorization
|
|
13
|
+
// * @param authentication Authentication Port
|
|
14
|
+
// * @returns
|
|
15
|
+
// */
|
|
16
|
+
// export const LocalAuthorization = ( authentication: AuthenticationPort, database: DatabasePort ): LocalAuthorizationType => {
|
|
17
|
+
// const routeManager = authentication.RouteManager( database );
|
|
18
|
+
// const _authorizeRequest = authentication.authorizeRequest( routeManager );
|
|
19
|
+
|
|
20
|
+
// const authorizeRequest = async ( params: EndpointActionParams<any, any, any> ) => {
|
|
21
|
+
// await _authorizeRequest( params.context.token!, params.context.req?.method!, params.context.req?.route! );
|
|
22
|
+
// return params;
|
|
23
|
+
// };
|
|
24
|
+
|
|
25
|
+
// const registerEndpoint = ( endpoint: Endpoint ) => {
|
|
26
|
+
// const originalAction = endpoint.action;
|
|
27
|
+
// endpoint.action = ( params: EndpointActionParams<any, any, any> ) => {
|
|
28
|
+
// return authorizeRequest( params )
|
|
29
|
+
// .then( originalAction );
|
|
30
|
+
// };
|
|
31
|
+
// return endpoint;
|
|
32
|
+
// };
|
|
33
|
+
|
|
34
|
+
// const registerRouteManagementEndpoints = ( endpoints: EndpointsPort ) => {
|
|
35
|
+
// const upsertEndpointAuth = ( patchValue?: Partial<RouteManagerEndpointAuth> ) => ({ body } : {body: {id: string}[]}) => {
|
|
36
|
+
// return Promise.all( body.map( compose(
|
|
37
|
+
// routeManager.upsertRoute,
|
|
38
|
+
// mergeRight( patchValue || {})
|
|
39
|
+
// )));
|
|
40
|
+
// };
|
|
41
|
+
|
|
42
|
+
// endpoints.registerEndpoint({
|
|
43
|
+
// module: 'Authorization',
|
|
44
|
+
// name: 'Mark as Public',
|
|
45
|
+
// description: 'Mark an endpoint as public',
|
|
46
|
+
// route: '/authorization/mark-as-public',
|
|
47
|
+
// method: 'POST',
|
|
48
|
+
// schemas: {
|
|
49
|
+
// body: S.array().items( EndpointMarkedAsPublicSchema )
|
|
50
|
+
// },
|
|
51
|
+
// action: upsertEndpointAuth({ isPublic:true })
|
|
52
|
+
// });
|
|
53
|
+
|
|
54
|
+
// endpoints.registerEndpoint({
|
|
55
|
+
// module: 'Authorization',
|
|
56
|
+
// name: 'Upsert Roles',
|
|
57
|
+
// description: 'Upsert roles for endpoint',
|
|
58
|
+
// route: '/authorization/upsert-roles',
|
|
59
|
+
// method: 'POST',
|
|
60
|
+
// schemas: {
|
|
61
|
+
// body: S.array().items( EndpointRolesUpsertedSchema )
|
|
62
|
+
// },
|
|
63
|
+
// action: upsertEndpointAuth()
|
|
64
|
+
// });
|
|
65
|
+
// };
|
|
66
|
+
|
|
67
|
+
// return {
|
|
68
|
+
// _adapter: () => {},
|
|
69
|
+
// name: 'localAuthorization',
|
|
70
|
+
// registerRouteManagementEndpoints,
|
|
71
|
+
// start: async()=>{},
|
|
72
|
+
// stop: async()=>{},
|
|
73
|
+
// registerEndpoint
|
|
74
|
+
// };
|
|
75
|
+
// };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import S from '@bett3r-dev/jsonschema-definer';
|
|
2
|
+
import {
|
|
3
|
+
AppErrorInstance, ConfigurationPort, Endpoint,
|
|
4
|
+
EndpointAction,
|
|
5
|
+
EndpointsAdapter, LoggerPort,
|
|
6
|
+
TcpEventMessageRequest, TcpEventMessageResponse
|
|
7
|
+
} from '@bett3r-dev/pv3-types';
|
|
8
|
+
import { Socket } from 'net';
|
|
9
|
+
import { Tcp as TcpLib, TcpServerObject } from '../../../libraries/tcp';
|
|
10
|
+
|
|
11
|
+
const TcpConsumerConfigSchema = S.shape({
|
|
12
|
+
port: S.number().optional().default( 9520 ),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const TcpConsumer = ( configuration: ConfigurationPort, loggerPort: LoggerPort ): EndpointsAdapter => {
|
|
17
|
+
const { config } = configuration.getModuleConfig( 'tcpConsumer', TcpConsumerConfigSchema.optional());
|
|
18
|
+
const logger = loggerPort.createLoggerInstance( 'TcpConsumer' );
|
|
19
|
+
const tcp = TcpLib( loggerPort );
|
|
20
|
+
let server: TcpServerObject;
|
|
21
|
+
const endpointMap: Map<string, EndpointAction> = new Map();
|
|
22
|
+
|
|
23
|
+
const registerEndpoint = ( endpoint: Endpoint ): Endpoint => {
|
|
24
|
+
const { route, module, action } = endpoint;
|
|
25
|
+
logger.log( 'Registering TCP Consumer endpoint:', module, route );
|
|
26
|
+
endpointMap.set( route, action );
|
|
27
|
+
return endpoint;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const start = async ( port: number | undefined = config.port || 9520 ): Promise<void> =>{
|
|
31
|
+
tcp.createTCPServer( port ).then( _server => {
|
|
32
|
+
server = _server;
|
|
33
|
+
let broker: Socket;
|
|
34
|
+
logger.info( 'TCP server listening on port', port );
|
|
35
|
+
server.connectedStream.map(({ socket }) => broker = socket );
|
|
36
|
+
server.dataStream.map(({ message }) => {
|
|
37
|
+
const { endpoint, event } = JSON.parse( message ) as TcpEventMessageRequest;
|
|
38
|
+
const action = endpointMap.get( endpoint );
|
|
39
|
+
if ( !action ) logger.error( 'No endpoint found for', endpoint );
|
|
40
|
+
action!({
|
|
41
|
+
body: event,
|
|
42
|
+
params: {},
|
|
43
|
+
query: {},
|
|
44
|
+
// TODO: Contemplar el contexto que viene del event?
|
|
45
|
+
context: {},
|
|
46
|
+
})
|
|
47
|
+
.then(() => {
|
|
48
|
+
broker.write( JSON.stringify({ id: event.id, status: 200 } as TcpEventMessageResponse ));
|
|
49
|
+
})
|
|
50
|
+
.catch(( e: AppErrorInstance ) => {
|
|
51
|
+
broker.write( JSON.stringify({ id: event.id, status: e.status, error: e.message } as TcpEventMessageResponse ));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const stop = () => new Promise<void>(( resolve, reject ) => {
|
|
58
|
+
return server.close();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
name: 'express',
|
|
63
|
+
adapterType: 'httpHandler',
|
|
64
|
+
_adapter: () => {},
|
|
65
|
+
registerEndpoint,
|
|
66
|
+
start,
|
|
67
|
+
stop,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CachePort, Endpoint, EndpointActionParams, EndpointsAdapter, LoggerPort } from '@bett3r-dev/pv3-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adds the user session object to the request context
|
|
5
|
+
* @param customTokenAttributes - Object with key as the path to the attribute in the token and value as the name of the attribute in the user object
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const UserSession = ( logger: LoggerPort, cache: CachePort, keyFormatter: ( user: Record<string, any> ) => string = ( user ) => user.id ): EndpointsAdapter => {
|
|
9
|
+
const log = logger.createLoggerInstance( 'UserSessionEndpointsAdapter' );
|
|
10
|
+
const addUserSessionToContext = async ( params: EndpointActionParams ): Promise<EndpointActionParams> =>{
|
|
11
|
+
if ( !params.context?.user ) return params;
|
|
12
|
+
try{
|
|
13
|
+
const key = keyFormatter( params.context.user );
|
|
14
|
+
const session = await cache.get( key );
|
|
15
|
+
if ( !params.context )
|
|
16
|
+
params.context = {};
|
|
17
|
+
params.context.session = session;
|
|
18
|
+
} catch ( err ) {
|
|
19
|
+
log.error( err );
|
|
20
|
+
}
|
|
21
|
+
return Promise.resolve( params );
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const registerEndpoint = ( endpoint: Endpoint ) => {
|
|
25
|
+
const originalAction = endpoint.action;
|
|
26
|
+
endpoint.action = ( params: EndpointActionParams<any, any, any> ) => {
|
|
27
|
+
return addUserSessionToContext( params )
|
|
28
|
+
.then( originalAction );
|
|
29
|
+
};
|
|
30
|
+
return endpoint;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
_adapter: () => {},
|
|
35
|
+
name: 'addUserSessionToContext',
|
|
36
|
+
start: async()=>{},
|
|
37
|
+
stop: async()=>{},
|
|
38
|
+
registerEndpoint
|
|
39
|
+
};
|
|
40
|
+
};
|