podmanager 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Podman Web UI API Client
3
+ */
4
+ const API = {
5
+ async request(endpoint, options = {}) {
6
+ const defaultHeaders = {
7
+ 'Accept': 'application/json',
8
+ ...(options.body && typeof options.body === 'object' && !(options.body instanceof FormData)
9
+ ? { 'Content-Type': 'application/json' }
10
+ : {})
11
+ };
12
+
13
+ const config = {
14
+ ...options,
15
+ headers: {
16
+ ...defaultHeaders,
17
+ ...options.headers
18
+ }
19
+ };
20
+
21
+ if (config.body && typeof config.body === 'object' && !(config.body instanceof FormData)) {
22
+ config.body = JSON.stringify(config.body);
23
+ }
24
+
25
+ try {
26
+ const response = await fetch(endpoint, config);
27
+ const data = await response.json().catch(() => null);
28
+
29
+ if (!response.ok) {
30
+ const errorMsg = data?.error || data?.stderr || `Request failed with status ${response.status}`;
31
+ const err = new Error(errorMsg);
32
+ err.data = data;
33
+ err.status = response.status;
34
+ throw err;
35
+ }
36
+
37
+ return data;
38
+ } catch (err) {
39
+ console.error(`API Error on [${options.method || 'GET'} ${endpoint}]:`, err);
40
+ throw err;
41
+ }
42
+ },
43
+
44
+ // System
45
+ getSystemInfo() {
46
+ return this.request('/api/system/info');
47
+ },
48
+ getSystemDf() {
49
+ return this.request('/api/system/df');
50
+ },
51
+ pruneSystem(type = 'all') {
52
+ return this.request('/api/system/prune', { method: 'POST', body: { type } });
53
+ },
54
+
55
+ // Containers
56
+ getContainers(all = true) {
57
+ return this.request(`/api/containers?all=${all}`);
58
+ },
59
+ inspectContainer(id) {
60
+ return this.request(`/api/containers/${id}`);
61
+ },
62
+ createContainer(payload) {
63
+ return this.request('/api/containers', { method: 'POST', body: payload });
64
+ },
65
+ startContainer(id) {
66
+ return this.request(`/api/containers/${id}/start`, { method: 'POST' });
67
+ },
68
+ stopContainer(id, timeout = 10) {
69
+ return this.request(`/api/containers/${id}/stop`, { method: 'POST', body: { timeout } });
70
+ },
71
+ restartContainer(id, timeout = 10) {
72
+ return this.request(`/api/containers/${id}/restart`, { method: 'POST', body: { timeout } });
73
+ },
74
+ killContainer(id, signal = 'SIGKILL') {
75
+ return this.request(`/api/containers/${id}/kill`, { method: 'POST', body: { signal } });
76
+ },
77
+ pauseContainer(id) {
78
+ return this.request(`/api/containers/${id}/pause`, { method: 'POST' });
79
+ },
80
+ unpauseContainer(id) {
81
+ return this.request(`/api/containers/${id}/unpause`, { method: 'POST' });
82
+ },
83
+ removeContainer(id, force = false, volumes = false) {
84
+ return this.request(`/api/containers/${id}?force=${force}&volumes=${volumes}`, { method: 'DELETE' });
85
+ },
86
+ getContainerLogs(id, tail = 100, timestamps = false) {
87
+ return this.request(`/api/containers/${id}/logs?tail=${tail}&timestamps=${timestamps}`);
88
+ },
89
+ execContainer(id, command, workdir) {
90
+ return this.request(`/api/containers/${id}/exec`, { method: 'POST', body: { command, workdir } });
91
+ },
92
+
93
+ // Pods
94
+ getPods() {
95
+ return this.request('/api/pods');
96
+ },
97
+ inspectPod(id) {
98
+ return this.request(`/api/pods/${id}`);
99
+ },
100
+ createPod(payload) {
101
+ return this.request('/api/pods', { method: 'POST', body: payload });
102
+ },
103
+ startPod(id) {
104
+ return this.request(`/api/pods/${id}/start`, { method: 'POST' });
105
+ },
106
+ stopPod(id) {
107
+ return this.request(`/api/pods/${id}/stop`, { method: 'POST' });
108
+ },
109
+ restartPod(id) {
110
+ return this.request(`/api/pods/${id}/restart`, { method: 'POST' });
111
+ },
112
+ removePod(id, force = false) {
113
+ return this.request(`/api/pods/${id}?force=${force}`, { method: 'DELETE' });
114
+ },
115
+
116
+ // Images
117
+ getImages() {
118
+ return this.request('/api/images');
119
+ },
120
+ inspectImage(id) {
121
+ return this.request(`/api/images/${id}`);
122
+ },
123
+ pullImage(image) {
124
+ return this.request('/api/images/pull', { method: 'POST', body: { image } });
125
+ },
126
+ removeImage(id, force = false) {
127
+ return this.request(`/api/images/${id}?force=${force}`, { method: 'DELETE' });
128
+ },
129
+
130
+ // Volumes
131
+ getVolumes() {
132
+ return this.request('/api/volumes');
133
+ },
134
+ inspectVolume(name) {
135
+ return this.request(`/api/volumes/${encodeURIComponent(name)}`);
136
+ },
137
+ createVolume(name, driver) {
138
+ return this.request('/api/volumes', { method: 'POST', body: { name, driver } });
139
+ },
140
+ removeVolume(name, force = false) {
141
+ return this.request(`/api/volumes/${encodeURIComponent(name)}?force=${force}`, { method: 'DELETE' });
142
+ },
143
+
144
+ // Networks
145
+ getNetworks() {
146
+ return this.request('/api/networks');
147
+ },
148
+ inspectNetwork(name) {
149
+ return this.request(`/api/networks/${encodeURIComponent(name)}`);
150
+ },
151
+ createNetwork(payload) {
152
+ return this.request('/api/networks', { method: 'POST', body: payload });
153
+ },
154
+ removeNetwork(name) {
155
+ return this.request(`/api/networks/${encodeURIComponent(name)}`, { method: 'DELETE' });
156
+ },
157
+
158
+ // Events
159
+ getEvents(since = '24h') {
160
+ return this.request(`/api/events?since=${encodeURIComponent(since)}`);
161
+ }
162
+ };