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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 | (ns ird.p2p
"P2P apps: signalling/relay infrastructure with TURN credentials, an
offline mailbox, origin control and custom domains."
(:require
[ird.gate :as gate]
[ird.transport :as transport]))
(defn list-apps
"GET /p2p/apps — List your p2p apps.
Returns the parsed response map."
[client]
(transport/request client :get "/p2p/apps"))
(defn create-app
"POST /p2p/apps — Create a p2p app.
BODY keys include :name, :origins, :settings and :mailbox_enabled (the
offline mailbox is off by default).
Returns the parsed response map."
[client body]
(transport/request client :post "/p2p/apps" {:body body}))
(defn get-app
"GET /p2p/apps/{id} — P2P app detail.
Returns the parsed response map."
[client id]
(transport/request client :get (str "/p2p/apps/" id)))
(defn delete-app
"DELETE /p2p/apps/{id} — Delete a p2p app.
Returns the parsed response map."
[client id]
(transport/request client :delete (str "/p2p/apps/" id)))
(defn update-app
"PATCH /p2p/apps/{id} — Update app origins/settings/relay/mailbox.
BODY keys include :origins, :settings, :relay_enabled, :mailbox_enabled
and :mailbox_open_mint (turn open minting off to hand out mailbox tokens
only from your own backend via `mint-mailbox-credentials`).
Returns the parsed response map."
[client id body]
(transport/request client :patch (str "/p2p/apps/" id) {:body body}))
(defn mint-turn-credentials
"POST /p2p/apps/{id}/turn-credentials — Mint TURN credentials.
Optional BODY carries :ttl_sec.
Returns the parsed response map."
([client id] (mint-turn-credentials client id nil))
([client id body]
(transport/request client :post (str "/p2p/apps/" id "/turn-credentials")
(when body {:body body}))))
(defn mint-mailbox-credentials
"POST /p2p/apps/{id}/mailbox-credentials — Mint a short-lived bearer token
for the app's offline mailbox (requires :mailbox_enabled on the app).
Optional BODY carries :room (scope the token to one rendezvous id; omit
for an app-wide token) and :ttl_sec (default 3600, capped at 86400).
Returns the parsed response map; its :credentials carry the :token and the
:endpoint (`https://<hostname>/mailbox/v1`) to send it to — that mailbox
data plane lives on the p2p node and is not part of this client."
([client id] (mint-mailbox-credentials client id nil))
([client id body]
(transport/request client :post (str "/p2p/apps/" id "/mailbox-credentials")
(when body {:body body}))))
(defn list-app-domains
"GET /p2p/apps/{id}/domains — List an app's custom domains.
Returns the parsed response map."
[client id]
(transport/request client :get (str "/p2p/apps/" id "/domains")))
(defn attach-domain
"POST /p2p/apps/{id}/domains — Attach a custom domain.
BODY keys include :hostname and optional :wildcard. Subject to the
client's domain gate on :hostname.
Returns the parsed response map."
[client id body]
(gate/check! client "POST /p2p/apps/{id}/domains" {:domain (:hostname body)})
(transport/request client :post (str "/p2p/apps/" id "/domains")
{:body body}))
(defn detach-domain
"DELETE /p2p/apps/{id}/domains/{domain-id} — Detach a custom domain.
Subject to the client's domain gate on the domain's hostname (resolved
via `list-app-domains` when a gate is set).
Returns the parsed response map."
[client id domain-id]
(when (:gate client)
(let [hostname (some #(when (= (str domain-id) (str (:id %))) (:hostname %))
(:domains (list-app-domains client id)))]
(gate/check! client "DELETE /p2p/apps/{id}/domains/{domain-id}"
{:domain hostname})))
(transport/request client :delete (str "/p2p/apps/" id "/domains/" domain-id)))
(defn verify-domain-dns
"POST /p2p/apps/{id}/domains/{domain-id}/verify-dns — Re-check a domain's
DNS.
Returns the parsed response map."
[client id domain-id]
(transport/request client :post
(str "/p2p/apps/" id "/domains/" domain-id "/verify-dns")))
(defn usage
"GET /p2p/usage — P2P usage and cost.
Returns the parsed response map."
[client]
(transport/request client :get "/p2p/usage"))
|