generated from coulomb/repo-seed
1.8 KiB
1.8 KiB
Examples
Register An Application And Catalog
from user_engine.adapters.local import InMemoryUserEngineStore, LocalAuthorizationCheckPort
from user_engine.service import UserEngineService
from user_engine.testing.fixtures import (
FixtureIdentityClaimsAdapter,
human_actor_claims,
sample_application,
sample_application_binding,
sample_catalog,
)
service = UserEngineService(
store=InMemoryUserEngineStore(),
identity_adapter=FixtureIdentityClaimsAdapter(),
authorization=LocalAuthorizationCheckPort(),
)
session = service.me(human_actor_claims(), correlation_id="corr-me")
service.register_application(
session.actor,
sample_application(),
binding=sample_application_binding(),
correlation_id="corr-app",
)
service.publish_catalog(session.actor, sample_catalog(), correlation_id="corr-cat")
Request An Application Projection
from user_engine.domain import ProfileScope, ProjectionType
service.set_profile_value(
session.actor,
session.user.user_id,
"demo.display_density",
"compact",
scope=ProfileScope.APPLICATION,
scope_id="app.demo",
tenant="tenant:coulomb",
application_id="app.demo",
correlation_id="corr-profile",
)
projection = service.projection(
session.actor,
session.user.user_id,
ProjectionType.APPLICATION_RUNTIME,
tenant="tenant:coulomb",
application_id="app.demo",
correlation_id="corr-projection",
)
Handle Profile Change Events
Profile mutations append audit records and outbox events in the same service
operation. Outbox consumers should treat event_id as the delivery id and
correlation_id as the cross-system trace key.
for event in service.outbox_events():
print(event.event_type, event.aggregate_id, event.correlation_id)