Elixir SDK for Pocketenv
1defmodule Sandbox.Types do
2 @moduledoc """
3 Types and structs used by the Pocketenv Sandbox SDK.
4 """
5
6 defmodule Profile do
7 @moduledoc "Represents a Pocketenv user profile."
8
9 @type t :: %__MODULE__{
10 id: String.t() | nil,
11 did: String.t(),
12 handle: String.t(),
13 display_name: String.t() | nil,
14 avatar: String.t() | nil,
15 created_at: String.t() | nil,
16 updated_at: String.t() | nil
17 }
18
19 defstruct [:id, :did, :handle, :display_name, :avatar, :created_at, :updated_at]
20
21 @doc "Build a Profile from the raw API map."
22 def from_map(map) when is_map(map) do
23 %__MODULE__{
24 id: map["id"],
25 did: map["did"],
26 handle: map["handle"],
27 display_name: map["displayName"],
28 avatar: map["avatar"],
29 created_at: map["createdAt"],
30 updated_at: map["updatedAt"]
31 }
32 end
33 end
34
35 defmodule Port do
36 @moduledoc "Represents an exposed port on a sandbox."
37
38 @type t :: %__MODULE__{
39 port: integer(),
40 description: String.t() | nil,
41 preview_url: String.t() | nil
42 }
43
44 defstruct [:port, :description, :preview_url]
45
46 @doc "Build a Port from the raw API map."
47 def from_map(map) when is_map(map) do
48 %__MODULE__{
49 port: map["port"],
50 description: map["description"],
51 preview_url: map["previewUrl"]
52 }
53 end
54 end
55
56 defmodule ExecResult do
57 @moduledoc "Represents the result of executing a command in a sandbox."
58
59 @type t :: %__MODULE__{
60 stdout: String.t(),
61 stderr: String.t(),
62 exit_code: integer()
63 }
64
65 defstruct stdout: "", stderr: "", exit_code: 0
66
67 @doc "Build an ExecResult from the raw API map."
68 def from_map(map) when is_map(map) do
69 %__MODULE__{
70 stdout: map["stdout"] || "",
71 stderr: map["stderr"] || "",
72 exit_code: map["exitCode"] || 0
73 }
74 end
75 end
76
77 defmodule Secret do
78 @moduledoc "Represents a secret stored in a sandbox."
79
80 @type t :: %__MODULE__{
81 id: String.t(),
82 name: String.t(),
83 created_at: String.t() | nil
84 }
85
86 defstruct [:id, :name, :created_at]
87
88 @doc "Build a Secret from the raw API map."
89 def from_map(map) when is_map(map) do
90 %__MODULE__{
91 id: map["id"],
92 name: map["name"],
93 created_at: map["createdAt"]
94 }
95 end
96 end
97
98 defmodule SshKey do
99 @moduledoc "Represents an SSH key pair associated with a sandbox."
100
101 @type t :: %__MODULE__{
102 id: String.t(),
103 private_key: String.t() | nil,
104 public_key: String.t() | nil,
105 created_at: String.t() | nil
106 }
107
108 defstruct [:id, :private_key, :public_key, :created_at]
109
110 @doc "Build an SshKey from the raw API map."
111 def from_map(map) when is_map(map) do
112 %__MODULE__{
113 id: map["id"],
114 private_key: map["privateKey"],
115 public_key: map["publicKey"],
116 created_at: map["createdAt"]
117 }
118 end
119 end
120
121 defmodule TailscaleAuthKey do
122 @moduledoc "Represents a Tailscale auth key associated with a sandbox."
123
124 @type t :: %__MODULE__{
125 id: String.t(),
126 auth_key: String.t() | nil,
127 created_at: String.t() | nil
128 }
129
130 defstruct [:id, :auth_key, :created_at]
131
132 @doc "Build a TailscaleAuthKey from the raw API map."
133 def from_map(map) when is_map(map) do
134 %__MODULE__{
135 id: map["id"],
136 auth_key: map["authKey"],
137 created_at: map["createdAt"]
138 }
139 end
140 end
141
142 defmodule Backup do
143 @moduledoc "Represents a sandbox backup."
144
145 @type t :: %__MODULE__{
146 id: String.t(),
147 directory: String.t(),
148 description: String.t() | nil,
149 expires_at: String.t() | nil,
150 created_at: String.t()
151 }
152
153 defstruct [:id, :directory, :description, :expires_at, :created_at]
154
155 @doc "Build a Backup from the raw API map."
156 def from_map(map) when is_map(map) do
157 %__MODULE__{
158 id: map["id"],
159 directory: map["directory"],
160 description: map["description"],
161 expires_at: map["expiresAt"],
162 created_at: map["createdAt"]
163 }
164 end
165 end
166end