ts / src / sharing.ts
297 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * 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 when configured.
 *
 * NOTE: every operation here requires an account JWT (see
 * `auth.deviceLogin`); API keys are not accepted.
 */
import type { Client } from './client.js';
import { checkGate } from './gate.js';
import * as http from './http.js';
import type { Body } from './types.js';

/** GET /domains/registrations/{id}/grants — Who has delegated access to this domain (outgoing). */
export const listDomainGrants = (client: Client, id: string) =>
  http.get(client, '/domains/registrations/{id}/grants', { params: { id } });

/** POST /domains/registrations/{id}/grants — Invite another customer to manage parts of this domain. */
export const invite = async (client: Client, id: string, body: Body<'/domains/registrations/{id}/grants', 'post'>) => {
  await checkGate(client, 'POST /domains/registrations/{id}/grants', { registrationId: id });
  return http.post(client, '/domains/registrations/{id}/grants', { params: { id }, body });
};

/** DELETE /domains/registrations/{id}/grants/{grant-id} — Revoke delegated access. */
export const revokeGrant = async (client: Client, id: string, grantId: string) => {
  await checkGate(client, 'DELETE /domains/registrations/{id}/grants/{grant-id}', { registrationId: id });
  return http.del(client, '/domains/registrations/{id}/grants/{grant-id}', { params: { id, 'grant-id': grantId } });
};

/** GET /grants — Domains shared with this account (incoming). */
export const listGrants = (client: Client) => http.get(client, '/grants');

/** POST /grants/{id}/accept — Accept a delegated-access invite. */
export const acceptGrant = (client: Client, id: string) => http.post(client, '/grants/{id}/accept', { params: { id } });

/** POST /grants/{id}/decline — Decline a delegated-access invite. */
export const declineGrant = (client: Client, id: string) =>
  http.post(client, '/grants/{id}/decline', { params: { id } });

/** POST /grants/{id}/leave — Walk away from an active grant. */
export const leaveGrant = (client: Client, id: string) => http.post(client, '/grants/{id}/leave', { params: { id } });

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/ts.git