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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335 | // Generated by scripts/gen-api.py from spec/openapi.json — do not edit.
import Foundation
// MARK: - Types
/// Values this build does not know decode as `.unrecognized`.
public enum TunnelStatus: RawRepresentable, Codable, Sendable, Hashable {
case pendingDns
case provisioning
case active
case degraded
case failed
case deleting
/// A value the server sent that this version of the package does not list.
case unrecognized(String)
/// Every value the spec listed when this file was generated.
public static let known: [TunnelStatus] = [.pendingDns, .provisioning, .active, .degraded, .failed, .deleting]
public init(rawValue: String) {
switch rawValue {
case "pending-dns": self = .pendingDns
case "provisioning": self = .provisioning
case "active": self = .active
case "degraded": self = .degraded
case "failed": self = .failed
case "deleting": self = .deleting
default: self = .unrecognized(rawValue)
}
}
public var rawValue: String {
switch self {
case .pendingDns: return "pending-dns"
case .provisioning: return "provisioning"
case .active: return "active"
case .degraded: return "degraded"
case .failed: return "failed"
case .deleting: return "deleting"
case .unrecognized(let raw): return raw
}
}
public init(from decoder: any Decoder) throws {
self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}
/// Shared by 6 operations.
public struct TunnelNode: Codable, Sendable, Hashable {
public var ipv4: String?
public var sshHost: String
public var sshPort: Int
public var sshUser: String
public init(ipv4: String? = nil, sshHost: String, sshPort: Int, sshUser: String) {
self.ipv4 = ipv4
self.sshHost = sshHost
self.sshPort = sshPort
self.sshUser = sshUser
}
enum CodingKeys: String, CodingKey {
case ipv4
case sshHost = "ssh_host"
case sshPort = "ssh_port"
case sshUser = "ssh_user"
}
/// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(ipv4, forKey: .ipv4)
try container.encode(sshHost, forKey: .sshHost)
try container.encode(sshPort, forKey: .sshPort)
try container.encode(sshUser, forKey: .sshUser)
}
}
/// Shared by 6 operations.
public struct TunnelSettings: Codable, Sendable, Hashable {
public var offlineIpns: String?
public init(offlineIpns: String? = nil) {
self.offlineIpns = offlineIpns
}
enum CodingKeys: String, CodingKey {
case offlineIpns = "offline_ipns"
}
}
/// Shared by 6 operations.
public struct Tunnel: Codable, Sendable, Hashable, Identifiable {
public var id: String
public var hostname: String
public var url: String
public var state: HostnameState
public var status: TunnelStatus
public var transport: String
public var port: Int
public var node: TunnelNode?
public var sshCommand: String?
/// Customer-tunable per-tunnel settings. `offline_ipns` (optional) holds the id of one of your IPNS names (`GET /ipfs/names`) — while your device is offline the tunnel serves that name's published content instead of the shared offline page.
public var settings: TunnelSettings
public var dnsOk: Bool?
public var dnsError: String?
public var dnsTarget: String?
public var dnsCnameTarget: String?
public var certStatus: CertStatus
public var clientConnected: Bool
/// Customer-facing summary of the last provisioning error, if any.
public var lastError: String?
public var subscriptionId: String?
public var createdAt: String?
public var updatedAt: String?
/// Present (true) in the list on a tunnel living on a domain another account shared with this one through a tunnel grant: manageable here, billed per the share's payer setting (the owner by default).
public var delegated: Bool?
public init(id: String, hostname: String, url: String, state: HostnameState, status: TunnelStatus, transport: String, port: Int, node: TunnelNode? = nil, sshCommand: String? = nil, settings: TunnelSettings, dnsOk: Bool? = nil, dnsError: String? = nil, dnsTarget: String? = nil, dnsCnameTarget: String? = nil, certStatus: CertStatus, clientConnected: Bool, lastError: String? = nil, subscriptionId: String? = nil, createdAt: String? = nil, updatedAt: String? = nil, delegated: Bool? = nil) {
self.id = id
self.hostname = hostname
self.url = url
self.state = state
self.status = status
self.transport = transport
self.port = port
self.node = node
self.sshCommand = sshCommand
self.settings = settings
self.dnsOk = dnsOk
self.dnsError = dnsError
self.dnsTarget = dnsTarget
self.dnsCnameTarget = dnsCnameTarget
self.certStatus = certStatus
self.clientConnected = clientConnected
self.lastError = lastError
self.subscriptionId = subscriptionId
self.createdAt = createdAt
self.updatedAt = updatedAt
self.delegated = delegated
}
enum CodingKeys: String, CodingKey {
case id
case hostname
case url
case state
case status
case transport
case port
case node
case sshCommand = "ssh_command"
case settings
case dnsOk = "dns_ok"
case dnsError = "dns_error"
case dnsTarget = "dns_target"
case dnsCnameTarget = "dns_cname_target"
case certStatus = "cert_status"
case clientConnected = "client_connected"
case lastError = "last_error"
case subscriptionId = "subscription_id"
case createdAt = "created_at"
case updatedAt = "updated_at"
case delegated
}
/// Explicit so required-but-nullable fields encode as `null` rather than vanishing.
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(hostname, forKey: .hostname)
try container.encode(url, forKey: .url)
try container.encode(state, forKey: .state)
try container.encode(status, forKey: .status)
try container.encode(transport, forKey: .transport)
try container.encode(port, forKey: .port)
try container.encode(node, forKey: .node)
try container.encode(sshCommand, forKey: .sshCommand)
try container.encode(settings, forKey: .settings)
try container.encode(dnsOk, forKey: .dnsOk)
try container.encode(dnsError, forKey: .dnsError)
try container.encode(dnsTarget, forKey: .dnsTarget)
try container.encode(dnsCnameTarget, forKey: .dnsCnameTarget)
try container.encode(certStatus, forKey: .certStatus)
try container.encode(clientConnected, forKey: .clientConnected)
try container.encode(lastError, forKey: .lastError)
try container.encode(subscriptionId, forKey: .subscriptionId)
try container.encode(createdAt, forKey: .createdAt)
try container.encode(updatedAt, forKey: .updatedAt)
try container.encodeIfPresent(delegated, forKey: .delegated)
}
}
/// Used by GET /tunnels.
public struct TunnelListResponse: Codable, Sendable, Hashable {
public var tunnels: [Tunnel]
public init(tunnels: [Tunnel]) {
self.tunnels = tunnels
}
enum CodingKeys: String, CodingKey {
case tunnels
}
}
/// Used by POST /tunnels.
public struct CreateTunnelBody: Codable, Sendable, Hashable {
public var hostname: String
public var sshPublicKey: String?
public var sshKeyId: String?
public var transport: String?
/// Per-tunnel settings; unknown keys are rejected. `offline_ipns` points the tunnel's offline page at one of your IPNS names (by id or label; stored as the id).
public var settings: TunnelSettings?
public var totpCode: String?
public init(hostname: String, sshPublicKey: String? = nil, sshKeyId: String? = nil, transport: String? = nil, settings: TunnelSettings? = nil, totpCode: String? = nil) {
self.hostname = hostname
self.sshPublicKey = sshPublicKey
self.sshKeyId = sshKeyId
self.transport = transport
self.settings = settings
self.totpCode = totpCode
}
enum CodingKeys: String, CodingKey {
case hostname
case sshPublicKey = "ssh_public_key"
case sshKeyId = "ssh_key_id"
case transport
case settings
case totpCode = "totp_code"
}
}
/// Shared by 5 operations.
public struct TunnelResponse: Codable, Sendable, Hashable {
public var tunnel: Tunnel
public init(tunnel: Tunnel) {
self.tunnel = tunnel
}
enum CodingKeys: String, CodingKey {
case tunnel
}
}
/// Used by PATCH /tunnels/{id}.
public struct UpdateTunnelBody: Codable, Sendable, Hashable {
/// The complete desired settings object.
public var settings: TunnelSettings
public var totpCode: String?
public init(settings: TunnelSettings, totpCode: String? = nil) {
self.settings = settings
self.totpCode = totpCode
}
enum CodingKeys: String, CodingKey {
case settings
case totpCode = "totp_code"
}
}
// MARK: - Operations
extension IrdOperation {
public static let tunnels_list = IrdOperation(method: .get, pathTemplate: "/tunnels", module: "tunnels", name: "list", security: .keyOrJwt)
public static let tunnels_create = IrdOperation(method: .post, pathTemplate: "/tunnels", module: "tunnels", name: "create", security: .keyOrJwt)
public static let tunnels_get = IrdOperation(method: .get, pathTemplate: "/tunnels/{id}", module: "tunnels", name: "get", security: .keyOrJwt)
public static let tunnels_remove = IrdOperation(method: .delete, pathTemplate: "/tunnels/{id}", module: "tunnels", name: "remove", security: .keyOrJwt)
public static let tunnels_update = IrdOperation(method: .patch, pathTemplate: "/tunnels/{id}", module: "tunnels", name: "update", security: .keyOrJwt)
public static let tunnels_verifyDns = IrdOperation(method: .post, pathTemplate: "/tunnels/{id}/verify-dns", module: "tunnels", name: "verifyDns", security: .keyOrJwt)
static let tunnelsOperations: [IrdOperation] = [.tunnels_list, .tunnels_create, .tunnels_get, .tunnels_remove, .tunnels_update, .tunnels_verifyDns]
}
/// The `tunnels` operations (6).
public struct TunnelsAPI: Sendable {
let client: IrdClient
/// List your tunnels
/// Every non-deleted HTTPS tunnel on the account. `status` is the customer-facing view: an `active` tunnel whose device is not currently connected reads `degraded`. Charged `tunnel.reads` per request.
/// `GET /tunnels` — 200
public func list() async throws -> TunnelListResponse {
try await client.request(.tunnels_list)
}
/// Create a tunnel
/// Provisions an HTTPS tunnel on your own domain or subdomain: a node and local port are allocated, the first prepaid hour is charged (`recurring.tunnel-hourly` — billing continues hourly, into a negative balance if needed, until you delete th…
/// `POST /tunnels` — 201
public func create(body: CreateTunnelBody) async throws -> TunnelResponse {
try await client.request(.tunnels_create, body: body)
}
/// Tunnel detail
/// One tunnel with its connection info and live status. Charged `tunnel.reads` per request.
/// `GET /tunnels/{id}` — 200
public func get(id: String) async throws -> TunnelResponse {
try await client.request(.tunnels_get, params: ["id": id])
}
/// Delete a tunnel
/// Stops billing immediately and tears the tunnel down on the node's next poll. Free — a negative balance never blocks stopping the tunnel that is billing you. Idempotent while deletion is in progress.
/// `DELETE /tunnels/{id}` — 200
public func remove(id: String, body: TotpCodeBody? = nil) async throws -> TunnelResponse {
try await client.request(.tunnels_remove, params: ["id": id], body: body)
}
/// Update tunnel settings
/// Replaces the tunnel's `settings` object (full-object replace through the allowlist — send the complete desired object; omitting a key clears it).
/// `PATCH /tunnels/{id}` — 200
public func update(id: String, body: UpdateTunnelBody) async throws -> TunnelResponse {
try await client.request(.tunnels_update, params: ["id": id], body: body)
}
/// Re-check DNS
/// Re-verifies that the tunnel hostname resolves to its node's IP (run it after fixing your records — a pass also retries a failed certificate). Charged `tunnel.reads` per request.
/// `POST /tunnels/{id}/verify-dns` — 200
public func verifyDns(id: String) async throws -> TunnelResponse {
try await client.request(.tunnels_verifyDns, params: ["id": id])
}
}
extension IrdClient {
public var tunnels: TunnelsAPI { TunnelsAPI(client: self) }
}
|