{"id":19503633,"url":"https://github.com/im-cloud-spain-connectors/python-connect-request-offline-criteria","last_synced_at":"2026-06-07T21:31:29.859Z","repository":{"id":78684789,"uuid":"589610103","full_name":"IM-Cloud-Spain-Connectors/python-connect-request-offline-criteria","owner":"IM-Cloud-Spain-Connectors","description":"Provides simple, flexible and extensible way to match offline Connect request.","archived":false,"fork":false,"pushed_at":"2023-11-03T13:01:52.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-08T10:39:56.106Z","etag":null,"topics":["component","connect","criteria","fulfillment","offline","python","request"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IM-Cloud-Spain-Connectors.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-16T14:23:01.000Z","updated_at":"2023-06-23T08:06:37.000Z","dependencies_parsed_at":"2024-11-10T22:22:42.776Z","dependency_job_id":"86a50094-409c-4d02-be78-8a54441d909f","html_url":"https://github.com/IM-Cloud-Spain-Connectors/python-connect-request-offline-criteria","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IM-Cloud-Spain-Connectors%2Fpython-connect-request-offline-criteria","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IM-Cloud-Spain-Connectors%2Fpython-connect-request-offline-criteria/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IM-Cloud-Spain-Connectors%2Fpython-connect-request-offline-criteria/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IM-Cloud-Spain-Connectors%2Fpython-connect-request-offline-criteria/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IM-Cloud-Spain-Connectors","download_url":"https://codeload.github.com/IM-Cloud-Spain-Connectors/python-connect-request-offline-criteria/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240754295,"owners_count":19852186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["component","connect","criteria","fulfillment","offline","python","request"],"created_at":"2024-11-10T22:22:25.778Z","updated_at":"2026-06-07T21:31:29.813Z","avatar_url":"https://github.com/IM-Cloud-Spain-Connectors.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Connect Request Offline Criteria\n\n[![Test](https://github.com/othercodes/python-connect-request-offline-criteria/actions/workflows/test.yml/badge.svg)](https://github.com/othercodes/python-connect-request-offline-criteria/actions/workflows/test.yml)\n\nProvides simple, flexible and extensible way to match offline Connect requests.\n\n## What is the offline mode?\n\nSome use cases requires specific operations in the connector side without calling the vendor system. Good examples are\nmigration operations or normalization process.\n\n## Installation\n\nThe easiest way to install the Connect Request Offline Criteria library is to get the latest version from PyPI:\n\n```bash\n# using poetry\npoetry add rndi-connect-request-offline-criteria\n# using pip\npip install rndi-connect-request-offline-criteria\n```\n\n## The Contracts\n\nThis package provides the following contracts or interfaces:\n\n```python\nclass OfflineChecker(ABC):\n    @abstractmethod\n    def is_offline_enabled(self, request: Union[dict, Request]) -\u003e bool:\n        \"\"\"\n        Evaluates if the given request is in offline mode or not.\n\n        :param request: Union[dict, Request] The Connect request object.\n        :return: bool True if the request is in offline mode, False otherwise.\n        \"\"\"\n```\n\nThe `OfflineChecker` exposes one single method `is_offline_enabled` that accepts the request dictionary and\nreturns `True` if the given request match the conditions to be considered as offline, `False` otherwise. All the given\nrules must match in order to consider a request as offline.\n\nEach condition or rule must have the following signature:\n\n```python\nRule = Callable[[dict], bool]\n```\n\nFor example, we can create a rule that will match all the requests in inquiring status as offline:\n\n```python\ndef match_request_type(request: dict) -\u003e bool:\n    return Request(request).type() == 'inquiring'\n```\n\n## The Adapters\n\nThis package comes with an adapter and some simple rules, check the example below:\n\n```python\nfrom rndi.connect.request_offline_criteria.adapters import OfflineCriteria\nfrom rndi.connect.request_offline_criteria.rules import (\n    match_request_type,\n    match_offline_asset_parameter,\n)\n\noffline = OfflineCriteria([\n    match_request_type,  # match the requests with type cancel and suspend.\n    match_offline_asset_parameter,  # match the request with value \"True\" in param \"offline_mode\". \n])\n\n# True if both filters match, False otherwise\nif offline.is_offline_enabled(request):\n    print(\"is offline model\")\nelse:\n    print(\"is online model\")\n```\n\nAlternatively, you can use the `OfflineCriteria` adapter as a business middleware to wrap business transactions:\n\n```python\nfrom rndi.connect.request_offline_criteria.adapters import OfflineCriteria\nfrom rndi.connect.request_offline_criteria.rules import match_request_type, match_offline_asset_parameter\nfrom rndi.connect.business_transactions.adapters import prepare\nfrom rndi.connect.business_transaction_middleware.middleware import make_middleware_callstack\n\n# get the business transaction\ntransaction = prepare(CreateCustomer())\n\n# instantiate the OfflineCriteria.\noffline = OfflineCriteria([\n    match_request_type,  # match the requests with type cancel and suspend.\n    match_offline_asset_parameter,  # match the request with value \"True\" in param \"offline_mode\". \n])\n\n# make the middleware callstack\ntransaction = make_middleware_callstack([offline], transaction)\n\n# execute the transaction normally, if the given request match the offline rules the request will be automatically \n# skipped without executing the actual transaction code. \nresponse = transaction(request)\n```\n\nAdditionally, you can trigger custom code on matching offline, by passing the `on_match` argument to\nthe `OfflineCriteria`\nclass on instantiation, for example, you can use the `DefaultOnMatchTransaction` class that comes with the package:\n\n```python\nfrom rndi.connect.request_offline_criteria.adapters import OfflineCriteria, DefaultOnMatchTransaction\nfrom rndi.connect.request_offline_criteria.rules import match_request_type, match_offline_asset_parameter\n\n# instantiate the OfflineCriteria.\noffline = OfflineCriteria([\n    match_request_type,  # match the requests with type cancel and suspend.\n    match_offline_asset_parameter,  # match the request with value \"True\" in param \"offline_mode\". \n], DefaultOnMatchTransaction(\"TL-662-440-096\", client, logger))\n```\n\nBy default, the `DefaultOnMatchTransaction` class will:\n\n* Log the message: `\"The subscription {id} is in offline mode.\"`.\n* Approve the request with the configured activation template.\n* Finish the transaction with `BackgroundResponse.done()`.\n\nOr simply use a callable that receives the request dictionary and returns a valid `BackgroundResponse`:\n\n```python\nfrom connect.eaas.core.responses import BackgroundResponse\nfrom rndi.connect.request_offline_criteria.adapters import OfflineCriteria\nfrom rndi.connect.request_offline_criteria.rules import match_request_type, match_offline_asset_parameter\n\n\ndef custom_offline_on_match(request: dict) -\u003e BackgroundResponse:\n    # do something custom here.\n    return BackgroundResponse.done()\n\n\noffline = OfflineCriteria([\n    match_request_type,\n    match_offline_asset_parameter,\n], custom_offline_on_match)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fim-cloud-spain-connectors%2Fpython-connect-request-offline-criteria","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fim-cloud-spain-connectors%2Fpython-connect-request-offline-criteria","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fim-cloud-spain-connectors%2Fpython-connect-request-offline-criteria/lists"}