NAH 1.0.6
Native Application Host - Library API Reference
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8namespace nah {
9
10// ============================================================================
11// Warning System (per SPEC L1359-L1383)
12// ============================================================================
13
37
38// Convert warning enum to canonical lowercase snake_case string
39inline const char* warning_to_string(Warning w) {
40 switch (w) {
41 case Warning::invalid_manifest: return "invalid_manifest";
42 case Warning::invalid_configuration: return "invalid_configuration";
43 case Warning::profile_invalid: return "profile_invalid";
44 case Warning::profile_missing: return "profile_missing";
45 case Warning::profile_parse_error: return "profile_parse_error";
46 case Warning::nak_pin_invalid: return "nak_pin_invalid";
47 case Warning::nak_not_found: return "nak_not_found";
48 case Warning::nak_version_unsupported: return "nak_version_unsupported";
49 case Warning::binary_not_found: return "binary_not_found";
50 case Warning::capability_missing: return "capability_missing";
51 case Warning::capability_malformed: return "capability_malformed";
52 case Warning::capability_unknown: return "capability_unknown";
53 case Warning::missing_env_var: return "missing_env_var";
54 case Warning::invalid_trust_state: return "invalid_trust_state";
55 case Warning::override_denied: return "override_denied";
56 case Warning::override_invalid: return "override_invalid";
57 case Warning::invalid_library_path: return "invalid_library_path";
58 case Warning::trust_state_unknown: return "trust_state_unknown";
59 case Warning::trust_state_unverified: return "trust_state_unverified";
60 case Warning::trust_state_failed: return "trust_state_failed";
61 case Warning::trust_state_stale: return "trust_state_stale";
62 default: return "unknown";
63 }
64}
65
66// Parse warning key string to enum (case-insensitive)
67std::optional<Warning> parse_warning_key(const std::string& key);
68
69// ============================================================================
70// Warning Action (per SPEC Host Profile warnings section)
71// ============================================================================
72
73enum class WarningAction {
74 Warn,
75 Ignore,
76 Error
77};
78
79inline const char* action_to_string(WarningAction a) {
80 switch (a) {
81 case WarningAction::Warn: return "warn";
82 case WarningAction::Ignore: return "ignore";
83 case WarningAction::Error: return "error";
84 default: return "warn";
85 }
86}
87
88std::optional<WarningAction> parse_warning_action(const std::string& s);
89
90// ============================================================================
91// Critical Errors (per SPEC L1386-L1391)
92// ============================================================================
93
100
102 switch (e) {
103 case CriticalError::MANIFEST_MISSING: return "MANIFEST_MISSING";
104 case CriticalError::ENTRYPOINT_NOT_FOUND: return "ENTRYPOINT_NOT_FOUND";
105 case CriticalError::PATH_TRAVERSAL: return "PATH_TRAVERSAL";
106 case CriticalError::INSTALL_RECORD_INVALID: return "INSTALL_RECORD_INVALID";
107 default: return "UNKNOWN";
108 }
109}
110
111// ============================================================================
112// Warning Object (per SPEC L1636-L1640)
113// ============================================================================
114
116 std::string key; // lowercase snake_case
117 std::string action; // "warn" | "error"
118 std::unordered_map<std::string, std::string> fields; // warning-specific
119};
120
121// ============================================================================
122// Trust State (per SPEC L470-L471)
123// ============================================================================
124
125enum class TrustState {
126 Verified,
128 Failed,
129 Unknown
130};
131
132inline const char* trust_state_to_string(TrustState s) {
133 switch (s) {
134 case TrustState::Verified: return "verified";
135 case TrustState::Unverified: return "unverified";
136 case TrustState::Failed: return "failed";
137 case TrustState::Unknown: return "unknown";
138 default: return "unknown";
139 }
140}
141
142std::optional<TrustState> parse_trust_state(const std::string& s);
143
144// ============================================================================
145// Trust Info (per SPEC L339-L359, L1280-L1285)
146// ============================================================================
147
148struct TrustInfo {
150 std::string source;
151 std::string evaluated_at; // RFC3339 timestamp
152 std::string expires_at; // RFC3339 timestamp (optional)
153 std::string inputs_hash; // optional
154 std::unordered_map<std::string, std::string> details; // host-defined opaque metadata
155};
156
157// ============================================================================
158// Asset Export (per SPEC L1287, L1305)
159// ============================================================================
160
162 std::string id;
163 std::string path; // absolute path under app.root
164 std::string type; // optional
165};
166
167// ============================================================================
168// Capability Usage (per SPEC L1290-L1294)
169// ============================================================================
170
172 bool present = false;
173 std::vector<std::string> required_capabilities;
174 std::vector<std::string> optional_capabilities; // empty in v1.0
175 std::vector<std::string> critical_capabilities; // empty in v1.0
176};
177
178// ============================================================================
179// Launch Contract (per SPEC L1248-L1296)
180// ============================================================================
181
183 struct {
184 std::string id;
185 std::string version;
186 std::string root;
187 std::string entrypoint;
189
190 struct {
191 std::string id;
192 std::string version;
193 std::string root;
194 std::string resource_root;
195 std::string record_ref;
197
198 struct {
199 std::string binary;
200 std::vector<std::string> arguments;
201 std::string cwd;
203 std::vector<std::string> library_paths;
205
206 std::unordered_map<std::string, std::string> environment;
207
208 struct {
209 std::vector<std::string> filesystem;
210 std::vector<std::string> network;
212
214
215 std::unordered_map<std::string, AssetExport> exports;
216
218};
219
220// ============================================================================
221// Trace Entry (per SPEC L1642-L1647)
222// ============================================================================
223
225 std::string value;
226 std::string source_kind; // profile | nak_record | manifest | install_record | process_env | overrides_file | standard
227 std::string source_path;
228 int precedence_rank; // 1..7
229};
230
231// ============================================================================
232// Contract Envelope (per SPEC L1654-L1658)
233// ============================================================================
234
237 std::vector<WarningObject> warnings;
238 std::optional<std::unordered_map<std::string, std::unordered_map<std::string, TraceEntry>>> trace;
239};
240
241// ============================================================================
242// Override Mode (per SPEC Host Profile overrides section)
243// ============================================================================
244
245enum class OverrideMode {
246 Allow,
247 Deny,
249};
250
252 switch (m) {
253 case OverrideMode::Allow: return "allow";
254 case OverrideMode::Deny: return "deny";
255 case OverrideMode::Allowlist: return "allowlist";
256 default: return "allow";
257 }
258}
259
260std::optional<OverrideMode> parse_override_mode(const std::string& s);
261
262// ============================================================================
263// Binding Mode (per SPEC L637-L652)
264// ============================================================================
265
266enum class BindingMode {
267 Canonical,
268 Mapped
269};
270
272 switch (m) {
273 case BindingMode::Canonical: return "canonical";
274 case BindingMode::Mapped: return "mapped";
275 default: return "canonical";
276 }
277}
278
279std::optional<BindingMode> parse_binding_mode(const std::string& s);
280
281// ============================================================================
282// Capability (per SPEC L1105-L1108)
283// ============================================================================
284
286 std::string key; // Full capability key (e.g., "fs.read./path")
287 std::string selector; // Resource selector (opaque) - deprecated, use resource
288 std::string operation; // The operation (read, write, execute, connect, listen, bind)
289 std::string resource; // The resource path or URL
290};
291
292// ============================================================================
293// NAK Pin (per SPEC L1154-L1158)
294// ============================================================================
295
296struct NakPin {
297 std::string id;
298 std::string version;
299 std::string record_ref;
300};
301
302// PinnedNakLoadResult is defined in nak_selection.hpp with full NakInstallRecord
303
304} // namespace nah
Error type with code and message.
Definition nahhost.hpp:77
Result type for fallible operations.
Definition nahhost.hpp:109
WarningAction
Definition types.hpp:73
BindingMode
Definition types.hpp:266
std::optional< BindingMode > parse_binding_mode(const std::string &s)
OverrideMode
Definition types.hpp:245
const char * override_mode_to_string(OverrideMode m)
Definition types.hpp:251
const char * action_to_string(WarningAction a)
Definition types.hpp:79
const char * warning_to_string(Warning w)
Definition types.hpp:39
const char * trust_state_to_string(TrustState s)
Definition types.hpp:132
Warning
Definition types.hpp:14
@ trust_state_unverified
@ nak_version_unsupported
std::optional< Warning > parse_warning_key(const std::string &key)
std::optional< WarningAction > parse_warning_action(const std::string &s)
std::optional< TrustState > parse_trust_state(const std::string &s)
CriticalError
Definition types.hpp:94
TrustState
Definition types.hpp:125
std::optional< OverrideMode > parse_override_mode(const std::string &s)
const char * critical_error_to_string(CriticalError e)
Definition types.hpp:101
const char * binding_mode_to_string(BindingMode m)
Definition types.hpp:271
std::string id
Definition types.hpp:162
std::string type
Definition types.hpp:164
std::string path
Definition types.hpp:163
std::vector< std::string > required_capabilities
Definition types.hpp:173
std::vector< std::string > optional_capabilities
Definition types.hpp:174
std::vector< std::string > critical_capabilities
Definition types.hpp:175
std::string selector
Definition types.hpp:287
std::string operation
Definition types.hpp:288
std::string key
Definition types.hpp:286
std::string resource
Definition types.hpp:289
std::optional< std::unordered_map< std::string, std::unordered_map< std::string, TraceEntry > > > trace
Definition types.hpp:238
std::vector< WarningObject > warnings
Definition types.hpp:237
LaunchContract contract
Definition types.hpp:236
std::string resource_root
Definition types.hpp:194
struct nah::LaunchContract::@24 enforcement
std::vector< std::string > library_paths
Definition types.hpp:203
std::vector< std::string > arguments
Definition types.hpp:200
TrustInfo trust
Definition types.hpp:213
std::vector< std::string > network
Definition types.hpp:210
std::unordered_map< std::string, AssetExport > exports
Definition types.hpp:215
std::string binary
Definition types.hpp:199
std::string root
Definition types.hpp:186
struct nah::LaunchContract::@21 app
std::unordered_map< std::string, std::string > environment
Definition types.hpp:206
struct nah::LaunchContract::@22 nak
std::string cwd
Definition types.hpp:201
std::string entrypoint
Definition types.hpp:187
struct nah::LaunchContract::@23 execution
std::string library_path_env_key
Definition types.hpp:202
std::string version
Definition types.hpp:185
std::vector< std::string > filesystem
Definition types.hpp:209
std::string id
Definition types.hpp:184
CapabilityUsage capability_usage
Definition types.hpp:217
std::string record_ref
Definition types.hpp:195
std::string version
Definition types.hpp:298
std::string record_ref
Definition types.hpp:299
std::string id
Definition types.hpp:297
std::string source_kind
Definition types.hpp:226
int precedence_rank
Definition types.hpp:228
std::string value
Definition types.hpp:225
std::string source_path
Definition types.hpp:227
std::string inputs_hash
Definition types.hpp:153
std::string source
Definition types.hpp:150
std::string expires_at
Definition types.hpp:152
std::string evaluated_at
Definition types.hpp:151
TrustState state
Definition types.hpp:149
std::unordered_map< std::string, std::string > details
Definition types.hpp:154
std::unordered_map< std::string, std::string > fields
Definition types.hpp:118
std::string action
Definition types.hpp:117
std::string key
Definition types.hpp:116