(ns ird.sharing
"Delegated access grants: invite other customers to manage parts of a
domain, and handle invites you receive. Inviting/revoking on a domain is
subject to the client's domain gate (ird.gate) when configured.
NOTE: every operation here requires an account JWT (see
ird.auth/device-login); API keys are not accepted."
(:require
[ird.gate :as gate]
[ird.transport :as transport]))
(defn list-domain-grants
"GET /domains/registrations/{id}/grants — Who has delegated access to
this domain (outgoing).
Returns the parsed response map."
[client id]
(transport/request client :get (str "/domains/registrations/" id "/grants")))
(defn invite
"POST /domains/registrations/{id}/grants — Invite another customer to
manage parts of this domain. BODY keys include :email, :scopes, :payer,
:totp_code.
Returns the parsed response map."
[client id body]
(gate/check! client "POST /domains/registrations/{id}/grants" {:registration-id id})
(transport/request client :post (str "/domains/registrations/" id "/grants")
{:body body}))
(defn revoke-grant
"DELETE /domains/registrations/{id}/grants/{grant-id} — Revoke delegated
access.
Returns the parsed response map."
[client id grant-id]
(gate/check! client "DELETE /domains/registrations/{id}/grants/{grant-id}" {:registration-id id})
(transport/request client :delete
(str "/domains/registrations/" id "/grants/" grant-id)))
(defn list-grants
"GET /grants — Domains shared with this account (incoming).
Returns the parsed response map."
[client]
(transport/request client :get "/grants"))
(defn accept-grant
"POST /grants/{id}/accept — Accept a delegated-access invite.
Returns the parsed response map."
[client id]
(transport/request client :post (str "/grants/" id "/accept")))
(defn decline-grant
"POST /grants/{id}/decline — Decline a delegated-access invite.
Returns the parsed response map."
[client id]
(transport/request client :post (str "/grants/" id "/decline")))
(defn leave-grant
"POST /grants/{id}/leave — Walk away from an active grant.
Returns the parsed response map."
[client id]
(transport/request client :post (str "/grants/" id "/leave")))