ts / dist / esm / p2p.js
391 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
42
43
44
import { checkGate } from './gate.js';
import * as http from './http.js';
/** GET /p2p/apps — List your p2p apps. */
export const listApps = (client) => http.get(client, '/p2p/apps');
/** POST /p2p/apps — Create a p2p app (the offline mailbox is off by default). */
export const createApp = (client, body) => http.post(client, '/p2p/apps', { body });
/** GET /p2p/apps/{id} — P2P app detail. */
export const getApp = (client, id) => http.get(client, '/p2p/apps/{id}', { params: { id } });
/** DELETE /p2p/apps/{id} — Delete a p2p app. */
export const deleteApp = (client, id) => http.del(client, '/p2p/apps/{id}', { params: { id } });
/** PATCH /p2p/apps/{id} — Update app origins/settings/relay/mailbox. */
export const updateApp = (client, id, body) => http.patch(client, '/p2p/apps/{id}', { params: { id }, body });
/** POST /p2p/apps/{id}/turn-credentials — Mint TURN credentials. */
export const mintTurnCredentials = (client, id, body) => http.post(client, '/p2p/apps/{id}/turn-credentials', { params: { id }, body });
/**
 * POST /p2p/apps/{id}/mailbox-credentials — Mint a short-lived bearer token
 * for the app's offline mailbox (requires `mailbox_enabled`). The response's
 * `credentials` carry the token and the endpoint to send it to; see
 * `mailbox`.
 */
export const mintMailboxCredentials = (client, id, body) => http.post(client, '/p2p/apps/{id}/mailbox-credentials', { params: { id }, body });
/** GET /p2p/apps/{id}/domains — List an app's custom domains. */
export const listAppDomains = (client, id) => http.get(client, '/p2p/apps/{id}/domains', { params: { id } });
/** POST /p2p/apps/{id}/domains — Attach a custom domain. Gated on `hostname`. */
export const attachDomain = async (client, id, body) => {
    await checkGate(client, 'POST /p2p/apps/{id}/domains', { domain: body.hostname });
    return http.post(client, '/p2p/apps/{id}/domains', { params: { id }, body });
};
/**
 * DELETE /p2p/apps/{id}/domains/{domain-id} — Detach a custom domain. Gated
 * on the domain's hostname (resolved via `listAppDomains` when a gate is set).
 */
export const detachDomain = async (client, id, domainId) => {
    if (client.gate) {
        const { domains } = await listAppDomains(client, id);
        const hostname = domains?.find((d) => String(d.id) === domainId)?.hostname;
        await checkGate(client, 'DELETE /p2p/apps/{id}/domains/{domain-id}', { domain: hostname });
    }
    return http.del(client, '/p2p/apps/{id}/domains/{domain-id}', { params: { id, 'domain-id': domainId } });
};
/** POST /p2p/apps/{id}/domains/{domain-id}/verify-dns — Re-check a domain's DNS. */
export const verifyDomainDns = (client, id, domainId) => http.post(client, '/p2p/apps/{id}/domains/{domain-id}/verify-dns', { params: { id, 'domain-id': domainId } });
/** GET /p2p/usage — P2P usage and cost. */
export const usage = (client) => http.get(client, '/p2p/usage');

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