Metadata-Version: 2.5
Name: trytond_score_api
Version: 8.0.0.1
Summary: Score Workflow Engine — External HTTP API
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: api,engine,http,portal,score,tryton,workflow
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Requires-Python: >=3.10
Requires-Dist: trytond-company<8.1,>=8.0
Requires-Dist: trytond-keycloak-auth<8.1,>=8.0
Requires-Dist: trytond-score<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Requires-Dist: trytond-score-task<8.1,>=8.0; extra == 'test'
Description-Content-Type: text/x-rst

Score API
=========

The ``score_api`` module exposes the workflow engine of the ``score``
family over HTTP, so that an external actor - a ``flask_board`` portal,
an automation script or a monitoring tool - reads and drives a run
without a Tryton client and without a direct database transaction.

What it serves is the *Integration Contract* the base module documents:
a caller is written against the instance number, the transition code and
the state code, never against a database identifier, and the Python API
the endpoints call is the one of ``score.engine``.

The endpoints
-------------

* ``GET /<database>/score/workflows?model=<model>`` - the workflows bound
  to a model.
* ``POST /<database>/score/instances`` - start a run on a record.
* ``GET /<database>/score/instances/<number>`` - read one run.
* ``GET /<database>/score/instances/<number>/transitions`` - the
  transitions the run may fire *now*.
* ``POST /<database>/score/instances/<number>/fire`` - fire a transition.
* ``GET /<database>/score/instances/<number>/history`` - the history of a
  run, paginated.
* ``GET /<database>/score/tasks``, ``GET /<database>/score/tasks/<id>``,
  ``POST /<database>/score/tasks/<id>/complete`` - the work items of the
  caller, when ``score_task`` is installed.

Security
--------

Every endpoint requires a Keycloak/OIDC bearer token, verified by
``keycloak_auth``: the identity is resolved to an *active* ``res.user``
by exact login, and nothing is provisioned on the way.  The endpoint
then runs as that user with the access checks of the ORM enabled and the
record rules of the user applied, so an endpoint never grants more than
the equivalent Python call would.

A state-changing request is made under an ``idempotency_key`` and is
answered with the answer the first request that used the key was given,
which is what keeps a retried HTTP request from firing a transition
twice.  The stored answer is validated against the append-only history
of the run it names.

The engine is always called with the ``api`` origin, and never with
``force`` or ``bypass_guards``: forcing a transition and overruling a
guard stay the decision of an administrator in the back office, where
the reason is recorded.  No endpoint of this module can be used to
bypass a guard.

Integration contract
--------------------

The endpoints, their payloads, their answers and the stable error codes
are documented in ``doc/routes.rst`` - that file is the contract a
portal is written against, and it is what a change to this module must
keep true.
