Metadata-Version: 2.5
Name: invenio-pidslink
Version: 0.3.0
Summary: InvenioRDM persistent identifier provider for ARKs minted through WACREN PIDsLink.
Project-URL: Repository, https://gitlab.wacren.net/libsense/invenio-pidslink
Author-email: Donald Doe Seanedzu <donald.seanedzu@wacren.net>
License-Expression: MIT
License-File: LICENSE
Keywords: ARK,Invenio,InvenioRDM,PID,PIDsLink,WACREN
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Flask
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.12
Requires-Dist: invenio-base<3.0.0,>=2.4.0
Requires-Dist: invenio-i18n<4.0.0,>=3.0.0
Requires-Dist: invenio-pidstore<4.0.0,>=3.0.0
Requires-Dist: invenio-rdm-records<33.0.0,>=32.0.0
Requires-Dist: requests>=2.31.0
Provides-Extra: tests
Requires-Dist: pytest-invenio<5.0.0,>=4.0.0; extra == 'tests'
Requires-Dist: pytest>=7.0.0; extra == 'tests'
Description-Content-Type: text/x-rst

================
Invenio-PIDsLink
================

InvenioRDM persistent identifier provider that mints **ARKs** through the
WACREN `PIDsLink <https://pidslink.ren.africa>`_ public API, authenticated with
an organisation API key.

Install
-------

.. code-block:: console

   pip install invenio-pidslink

Configure (``invenio.cfg``)
---------------------------

.. code-block:: python

   import os
   from invenio_i18n import lazy_gettext as _
   from invenio_rdm_records.services.pids import providers
   from invenio_pidslink.providers import PIDsLinkClient, PIDsLinkPIDProvider

   PIDSLINK_ENABLED = True
   PIDSLINK_API_KEY = os.environ["PIDSLINK_API_KEY"]   # server-side secret
   PIDSLINK_NAAN = "12345"
   PIDSLINK_SHOULDER = "abc"

   RDM_PERSISTENT_IDENTIFIER_PROVIDERS = [
       PIDsLinkPIDProvider("ark", client=PIDsLinkClient("pidslink"),
                           label=_("ARK")),
       providers.OAIPIDProvider("oai", label=_("OAI ID")),
   ]

   RDM_PERSISTENT_IDENTIFIERS = {
       "ark": {
           "providers": ["ark"],
           "required": True,
           "label": _("ARK"),
           "is_enabled": PIDsLinkPIDProvider.is_enabled,
           "system_managed": True,
       },
       "oai": {
           "providers": ["oai"],
           "required": True,
           "is_enabled": providers.OAIPIDProvider.is_enabled,
       },
   }

This example makes ARK the only system-managed identifier, because
``RDM_PERSISTENT_IDENTIFIERS`` replaces InvenioRDM's default (which includes
DOI). To offer ARKs *alongside* DOIs, keep InvenioRDM's default ``doi`` entry
in the dict and keep DataCite or Crossref enabled.

Showing the ARK and citations (optional)
----------------------------------------

The provider alone stores the ARK in the record's metadata. To show it on the
record page and in citations, opt in:

.. code-block:: python

   # invenio.cfg
   from invenio_app_rdm.config import APP_RDM_RECORD_EXPORTERS as DEFAULT_EXPORTERS
   from invenio_rdm_records.resources.config import record_serializers
   from invenio_pidslink.serializers import with_ark_exporters, with_ark_serializers

   RDM_RECORDS_SERIALIZERS = with_ark_serializers(record_serializers)
   APP_RDM_RECORD_EXPORTERS = with_ark_exporters(DEFAULT_EXPORTERS)

This makes the "Cite as" box, the ``text/x-bibliography`` and CSL JSON
responses, and the CSL export use the ARK resolver link
(``PIDSLINK_RESOLVER_URL``). For the landing page, include the template in your
record details sidebar override
(``templates/semantic-ui/invenio_app_rdm/records/details/side_bar/details.html``):

.. code-block:: jinja

   {% include "invenio_pidslink/ark_details.html" %}

Set ``{% set pidslink_show_missing = true %}`` first to show a notice for
records without an ARK. Templates can also call ``pidslink_ark_url(record)``.

Restricted records
------------------

InvenioRDM itself does not create required identifiers for records published as
*restricted*, so no ARK is minted for them (nothing is sent to PIDsLink). When a
restricted record is later made public and republished, it gets its ARK then.
``invenio pidslink mint`` follows the same rule and skips restricted records.

The reverse is different: a record that already has an ARK keeps it when it is
changed from public to restricted. A persistent identifier is never withdrawn,
so the ARK stays registered and keeps pointing at the record page, which the
public can no longer open. Making the record public again restores access with
the same ARK.

Public API coverage
-------------------

``invenio_pidslink.client.PIDsLinkClient`` wraps ``/api/public/pids/``:
``mint``, ``update``, ``query``, ``bulk_mint``, ``list``, ``stats``. It has no
Invenio dependency and can be used from plain scripts.

Development
-----------

.. code-block:: console

   pip install -e ".[tests]"
   ./run-tests.sh

Releases are published to PyPI by the GitLab CI ``publish`` job when a ``v*`` tag is pushed.

License: MIT.
