ds_provider_tripletex_py_lib.linked_service.tripletex ===================================================== .. py:module:: ds_provider_tripletex_py_lib.linked_service.tripletex .. autoapi-nested-parse:: **File:** ``tripletex.py`` **Region:** ``ds_provider_tripletex_py_lib/linked_service/tripletex`` Linked service for the Tripletex accounting API. Tripletex authenticates via a two-step token exchange: a long-lived *consumer token* + per-employee *employee token* are exchanged for a short-lived *session token*, combined with ``client_id`` into an HTTP Basic ``Authorization`` header (``Basic base64(client_id:session_token)``). This doesn't fit any of ``ds_protocol_http_py_lib``'s built-in ``AuthType`` handlers, so ``connect()`` is fully overridden; transport (retries, timeouts, rate limiting) is still inherited from ``HttpLinkedService``. .. rubric:: Example >>> linked_service = TripletexLinkedService( ... settings=TripletexLinkedServiceSettings( ... consumer_token="my-consumer-token", ... employee_token="my-employee-token", ... client_id="my-client-id", ... ), ... ) >>> linked_service.connect() >>> linked_service.connection.get(f"{linked_service.settings.host}/company") >>> linked_service.close() Attributes ---------- .. autoapisummary:: ds_provider_tripletex_py_lib.linked_service.tripletex.TripletexLinkedServiceSettingsType Classes ------- .. autoapisummary:: ds_provider_tripletex_py_lib.linked_service.tripletex.TripletexLinkedServiceSettings ds_provider_tripletex_py_lib.linked_service.tripletex.TripletexLinkedService Module Contents --------------- .. py:class:: TripletexLinkedServiceSettings Bases: :py:obj:`ds_protocol_http_py_lib.HttpLinkedServiceSettings` Settings required to connect to the Tripletex API. .. attribute:: consumer_token Long-lived consumer token issued to the integration. Masked in logs. .. attribute:: employee_token Per-employee token issued by the Tripletex user. Masked in logs. .. attribute:: client_id Client identifier combined with the session token to form the Basic auth header. Tripletex accepts ``"0"`` for the default/anonymous client. .. attribute:: host API host. Defaults to the production host; pass ``host=`` explicitly to target a different environment. .. attribute:: session_token_ttl_days Requested validity window, in days, for the session token created during ``connect()``. .. attribute:: auth_type Unused by this provider -- ``connect()`` is fully overridden and never dispatches through the base class's auth handlers. Kept only for schema/dataclass alignment with ``HttpLinkedServiceSettings``. .. py:attribute:: consumer_token :type: str Long-lived consumer token issued to the integration. .. py:attribute:: employee_token :type: str Per-employee token issued by the Tripletex user. .. py:attribute:: client_id :type: str :value: '0' Client identifier combined with the session token to form the Basic auth header. .. py:attribute:: host :type: str :value: 'https://tripletex.no/v2' API host. Defaults to the Tripletex production environment. .. py:attribute:: session_token_ttl_days :type: int :value: 1 Requested validity window, in days, for the session token. .. py:attribute:: auth_type :type: ds_protocol_http_py_lib.enums.AuthType Unused -- ``connect()`` is fully overridden. Kept for dataclass alignment. .. py:data:: TripletexLinkedServiceSettingsType .. py:class:: TripletexLinkedService Bases: :py:obj:`ds_protocol_http_py_lib.HttpLinkedService`\ [\ :py:obj:`TripletexLinkedServiceSettingsType`\ ], :py:obj:`Generic`\ [\ :py:obj:`TripletexLinkedServiceSettingsType`\ ] Linked service for connecting to the Tripletex API. Exposed (caller-configurable): ``id``, ``name``, ``description``, ``version``, ``settings``. Internal (inherited from ``HttpLinkedService``, ``init=False``, never user-settable): ``_session``, ``_http`` -- runtime connection state populated by ``connect()``. .. py:attribute:: settings :type: TripletexLinkedServiceSettingsType .. py:property:: type :type: ds_provider_tripletex_py_lib.enums.ResourceType Return the resource type for the Tripletex linked service. .. py:method:: connect() -> None Exchange consumer/employee tokens for a session token and build the auth header. ``PUT``s ``{host}/token/session/:create`` with ``consumerToken``/ ``employeeToken``/``expirationDate``, reads the session token from ``value.token``, then stores ``Basic base64(client_id:session_token)`` as the ``Authorization`` header. Idempotent -- each call creates a fresh session token. :raises AuthenticationError: If Tripletex responds but rejects the consumer/employee token (any non-2xx response other than 403, e.g. a revoked or malformed employee token returns 404/422, not 401 -- Tripletex's own message is included), or if the session token is missing from an otherwise-successful response. :raises AuthorizationError: If Tripletex returns 403 (authenticated but insufficient permission). :raises ConnectionError: If the request to Tripletex fails at the network level, or Tripletex never responds at all (e.g. a timeout) -- distinct from a response that arrives but rejects the request. .. py:method:: test_connection() -> tuple[bool, str] Verify the Tripletex session by calling the lightweight identity endpoint. :returns: ``(True, "")`` on success, otherwise ``(False, error_message)``. :rtype: tuple[bool, str]