een-api-toolkit 0.3.47 → 0.3.49

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.
Files changed (42) hide show
  1. package/.claude/agents/een-jobs-agent.md +676 -0
  2. package/CHANGELOG.md +7 -8
  3. package/dist/index.cjs +3 -3
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +1172 -28
  6. package/dist/index.js +796 -333
  7. package/dist/index.js.map +1 -1
  8. package/docs/AI-CONTEXT.md +22 -1
  9. package/docs/ai-reference/AI-AUTH.md +1 -1
  10. package/docs/ai-reference/AI-AUTOMATIONS.md +1 -1
  11. package/docs/ai-reference/AI-DEVICES.md +1 -1
  12. package/docs/ai-reference/AI-EVENTS.md +1 -1
  13. package/docs/ai-reference/AI-GROUPING.md +1 -1
  14. package/docs/ai-reference/AI-JOBS.md +1084 -0
  15. package/docs/ai-reference/AI-MEDIA.md +1 -1
  16. package/docs/ai-reference/AI-SETUP.md +1 -1
  17. package/docs/ai-reference/AI-USERS.md +1 -1
  18. package/examples/vue-jobs/.env.example +11 -0
  19. package/examples/vue-jobs/README.md +245 -0
  20. package/examples/vue-jobs/e2e/app.spec.ts +79 -0
  21. package/examples/vue-jobs/e2e/auth.spec.ts +382 -0
  22. package/examples/vue-jobs/e2e/delete-features.spec.ts +564 -0
  23. package/examples/vue-jobs/e2e/timelapse.spec.ts +361 -0
  24. package/examples/vue-jobs/index.html +13 -0
  25. package/examples/vue-jobs/package-lock.json +1722 -0
  26. package/examples/vue-jobs/package.json +28 -0
  27. package/examples/vue-jobs/playwright.config.ts +47 -0
  28. package/examples/vue-jobs/src/App.vue +154 -0
  29. package/examples/vue-jobs/src/main.ts +25 -0
  30. package/examples/vue-jobs/src/router/index.ts +82 -0
  31. package/examples/vue-jobs/src/views/Callback.vue +76 -0
  32. package/examples/vue-jobs/src/views/CreateExport.vue +284 -0
  33. package/examples/vue-jobs/src/views/Files.vue +424 -0
  34. package/examples/vue-jobs/src/views/Home.vue +195 -0
  35. package/examples/vue-jobs/src/views/JobDetail.vue +392 -0
  36. package/examples/vue-jobs/src/views/Jobs.vue +297 -0
  37. package/examples/vue-jobs/src/views/Login.vue +33 -0
  38. package/examples/vue-jobs/src/views/Logout.vue +59 -0
  39. package/examples/vue-jobs/src/vite-env.d.ts +1 -0
  40. package/examples/vue-jobs/tsconfig.json +25 -0
  41. package/examples/vue-jobs/vite.config.ts +12 -0
  42. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- import { defineStore as _e } from "pinia";
2
- import { ref as E, computed as q } from "vue";
3
- const he = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, ge = () => {
1
+ import { defineStore as ge } from "pinia";
2
+ import { ref as A, computed as F } from "vue";
3
+ const pe = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, Ee = () => {
4
4
  try {
5
- return he?.VITE_DEBUG === "true";
5
+ return pe?.VITE_DEBUG === "true";
6
6
  } catch {
7
7
  return !1;
8
8
  }
9
9
  };
10
10
  function s(...e) {
11
- ge() && console.log("[een-api-toolkit]", ...e);
11
+ Ee() && console.log("[een-api-toolkit]", ...e);
12
12
  }
13
- const Ne = {
13
+ const me = {
14
14
  localStorage: "persists across sessions",
15
15
  sessionStorage: "per-tab, cleared on tab close",
16
16
  memory: "tokens lost on page refresh"
17
17
  };
18
- class Re {
18
+ class Ae {
19
19
  store = /* @__PURE__ */ new Map();
20
20
  getItem(n) {
21
21
  return this.store.get(n) ?? null;
@@ -27,7 +27,7 @@ class Re {
27
27
  this.store.delete(n);
28
28
  }
29
29
  }
30
- class Y {
30
+ class te {
31
31
  constructor(n) {
32
32
  this.storage = n;
33
33
  }
@@ -41,49 +41,49 @@ class Y {
41
41
  this.storage.removeItem(n);
42
42
  }
43
43
  }
44
- let W = "localStorage", Q = null;
45
- function C() {
46
- return Q || (Q = new Re()), Q;
44
+ let K = "localStorage", C = null;
45
+ function x() {
46
+ return C || (C = new Ae()), C;
47
47
  }
48
- function pe(e) {
49
- W = e;
48
+ function Te(e) {
49
+ K = e;
50
50
  }
51
- function je() {
52
- return W;
51
+ function Be() {
52
+ return K;
53
53
  }
54
- function x() {
55
- switch (W) {
54
+ function V() {
55
+ switch (K) {
56
56
  case "memory":
57
- return C();
57
+ return x();
58
58
  case "sessionStorage":
59
- return typeof sessionStorage < "u" ? new Y(sessionStorage) : (s("sessionStorage unavailable, falling back to memory storage"), C());
59
+ return typeof sessionStorage < "u" ? new te(sessionStorage) : (s("sessionStorage unavailable, falling back to memory storage"), x());
60
60
  default:
61
- return typeof localStorage < "u" ? new Y(localStorage) : (s("localStorage unavailable, falling back to memory storage"), C());
61
+ return typeof localStorage < "u" ? new te(localStorage) : (s("localStorage unavailable, falling back to memory storage"), x());
62
62
  }
63
63
  }
64
- const $ = {};
64
+ const v = {};
65
65
  let b = {};
66
- function qe(e = {}) {
66
+ function Pe(e = {}) {
67
67
  const n = e.storageStrategy ?? "localStorage";
68
- pe(n), b = {
69
- proxyUrl: e.proxyUrl ?? $?.VITE_PROXY_URL,
70
- clientId: e.clientId ?? $?.VITE_EEN_CLIENT_ID,
71
- redirectUri: e.redirectUri ?? $?.VITE_REDIRECT_URI,
68
+ Te(n), b = {
69
+ proxyUrl: e.proxyUrl ?? v?.VITE_PROXY_URL,
70
+ clientId: e.clientId ?? v?.VITE_EEN_CLIENT_ID,
71
+ redirectUri: e.redirectUri ?? v?.VITE_REDIRECT_URI,
72
72
  storageStrategy: n,
73
- debug: e.debug ?? $?.VITE_DEBUG === "true"
73
+ debug: e.debug ?? v?.VITE_DEBUG === "true"
74
74
  };
75
75
  }
76
- function Fe() {
76
+ function He() {
77
77
  return b;
78
78
  }
79
- function K() {
80
- return b.proxyUrl ?? $?.VITE_PROXY_URL;
79
+ function M() {
80
+ return b.proxyUrl ?? v?.VITE_PROXY_URL;
81
81
  }
82
- function Ee() {
83
- return b.clientId ?? $?.VITE_EEN_CLIENT_ID;
82
+ function Ie() {
83
+ return b.clientId ?? v?.VITE_EEN_CLIENT_ID;
84
84
  }
85
- function Z() {
86
- return b.redirectUri ?? $?.VITE_REDIRECT_URI ?? "http://127.0.0.1:3333";
85
+ function ne() {
86
+ return b.redirectUri ?? v?.VITE_REDIRECT_URI ?? "http://127.0.0.1:3333";
87
87
  }
88
88
  function l(e) {
89
89
  return { data: e, error: null };
@@ -94,95 +94,95 @@ function i(e, n, t, r) {
94
94
  function I(e) {
95
95
  return e.endsWith("+00:00") ? e : e.endsWith("Z") ? e.replace("Z", "+00:00") : e;
96
96
  }
97
- let V = null;
98
- function Ae() {
99
- return V || (V = Promise.resolve().then(() => $e).then((e) => e.refreshToken)), V;
97
+ let W = null;
98
+ function Ue() {
99
+ return W || (W = Promise.resolve().then(() => ke).then((e) => e.refreshToken)), W;
100
100
  }
101
- const f = _e("een-auth", () => {
102
- const e = E(null), n = E(null), t = E(null), r = E(null), a = E(null), o = E(443), c = E(null), d = E(null), g = E(!1);
103
- let A = null;
104
- const p = E(!1), _ = E(null), S = q(() => !!e.value), v = q(() => a.value ? o.value === 443 ? `https://${a.value}` : `https://${a.value}:${o.value}` : null), R = q(() => n.value ? Date.now() >= n.value : !0), P = q(() => n.value ? Math.max(0, n.value - Date.now()) : 0);
105
- function H(u, h) {
106
- e.value = u, n.value = Date.now() + h * 1e3, D(), z(), s("Token set, expires in", h, "seconds");
101
+ const f = ge("een-auth", () => {
102
+ const e = A(null), n = A(null), t = A(null), r = A(null), a = A(null), o = A(443), c = A(null), u = A(null), R = A(!1);
103
+ let h = null;
104
+ const E = A(!1), _ = A(null), S = F(() => !!e.value), $ = F(() => a.value ? o.value === 443 ? `https://${a.value}` : `https://${a.value}:${o.value}` : null), p = F(() => n.value ? Date.now() >= n.value : !0), H = F(() => n.value ? Math.max(0, n.value - Date.now()) : 0);
105
+ function z(d, g) {
106
+ e.value = d, n.value = Date.now() + g * 1e3, O(), Q(), s("Token set, expires in", g, "seconds");
107
107
  }
108
- function N(u) {
109
- t.value = u, D();
108
+ function N(d) {
109
+ t.value = d, O();
110
110
  }
111
- function y(u) {
112
- r.value = u, D();
111
+ function y(d) {
112
+ r.value = d, O();
113
113
  }
114
- function O(u) {
115
- if (typeof u == "string")
114
+ function D(d) {
115
+ if (typeof d == "string")
116
116
  try {
117
- const h = new URL(u.startsWith("http") ? u : `https://${u}`);
118
- a.value = h.hostname, o.value = h.port ? parseInt(h.port, 10) : 443;
119
- } catch (h) {
120
- s("Failed to parse URL, using as hostname:", h instanceof Error ? h.message : String(h)), a.value = u, o.value = 443;
117
+ const g = new URL(d.startsWith("http") ? d : `https://${d}`);
118
+ a.value = g.hostname, o.value = g.port ? parseInt(g.port, 10) : 443;
119
+ } catch (g) {
120
+ s("Failed to parse URL, using as hostname:", g instanceof Error ? g.message : String(g)), a.value = d, o.value = 443;
121
121
  }
122
122
  else
123
- a.value = u.hostname, o.value = u.port ?? 443;
124
- D(), s("Base URL set:", v.value);
123
+ a.value = d.hostname, o.value = d.port ?? 443;
124
+ O(), s("Base URL set:", $.value);
125
125
  }
126
- function T(u) {
127
- c.value = u, D();
126
+ function T(d) {
127
+ c.value = d, O();
128
128
  }
129
- function z() {
130
- if (d.value && (clearTimeout(d.value), d.value = null), !n.value || !e.value)
129
+ function Q() {
130
+ if (u.value && (clearTimeout(u.value), u.value = null), !n.value || !e.value)
131
131
  return;
132
- const u = Date.now(), k = n.value - u, j = 300 * 1e3, de = k / 2, le = Math.min(j, de), fe = Math.max(k - le, 60 * 1e3), X = Math.max(fe, 5e3);
133
- s("Auto-refresh scheduled in", Math.round(X / 1e3), "seconds"), d.value = setTimeout(async () => {
134
- await oe();
135
- }, X);
132
+ const d = Date.now(), k = n.value - d, q = 300 * 1e3, _e = k / 2, Re = Math.min(q, _e), he = Math.max(k - Re, 60 * 1e3), ee = Math.max(he, 5e3);
133
+ s("Auto-refresh scheduled in", Math.round(ee / 1e3), "seconds"), u.value = setTimeout(async () => {
134
+ await se();
135
+ }, ee);
136
136
  }
137
- async function oe() {
138
- return A ? (s("Refresh already in progress, waiting for existing refresh"), A) : (g.value = !0, s("Performing auto-refresh"), A = (async () => {
137
+ async function se() {
138
+ return h ? (s("Refresh already in progress, waiting for existing refresh"), h) : (R.value = !0, s("Performing auto-refresh"), h = (async () => {
139
139
  try {
140
- const h = await (await Ae())();
141
- h.error ? (p.value = !0, _.value = h.error.message, s("Auto-refresh failed:", h.error.message)) : (p.value = !1, _.value = null, s("Auto-refresh successful"));
142
- } catch (u) {
143
- p.value = !0, _.value = u instanceof Error ? u.message : String(u), s("Auto-refresh error:", u);
140
+ const g = await (await Ue())();
141
+ g.error ? (E.value = !0, _.value = g.error.message, s("Auto-refresh failed:", g.error.message)) : (E.value = !1, _.value = null, s("Auto-refresh successful"));
142
+ } catch (d) {
143
+ E.value = !0, _.value = d instanceof Error ? d.message : String(d), s("Auto-refresh error:", d);
144
144
  } finally {
145
- g.value = !1, A = null;
145
+ R.value = !1, h = null;
146
146
  }
147
- })(), A);
147
+ })(), h);
148
148
  }
149
- function ae() {
150
- p.value = !1, _.value = null;
149
+ function ue() {
150
+ E.value = !1, _.value = null;
151
151
  }
152
- function J() {
153
- d.value && (clearTimeout(d.value), d.value = null), e.value = null, n.value = null, t.value = null, r.value = null, a.value = null, o.value = 443, c.value = null, p.value = !1, _.value = null, ue(), s("Logged out");
152
+ function Z() {
153
+ u.value && (clearTimeout(u.value), u.value = null), e.value = null, n.value = null, t.value = null, r.value = null, a.value = null, o.value = 443, c.value = null, E.value = !1, _.value = null, fe(), s("Logged out");
154
154
  }
155
- function ce() {
156
- se(), e.value && !R.value ? (z(), s("Initialized from storage")) : e.value && R.value && (s("Stored token expired, clearing"), J());
155
+ function de() {
156
+ le(), e.value && !p.value ? (Q(), s("Initialized from storage")) : e.value && p.value && (s("Stored token expired, clearing"), Z());
157
157
  }
158
- function D() {
158
+ function O() {
159
159
  try {
160
- const u = x();
161
- e.value && u.setItem("een_token", e.value), n.value && u.setItem("een_tokenExpiration", String(n.value)), t.value && u.setItem("een_refreshTokenMarker", t.value), r.value && u.setItem("een_sessionId", r.value), a.value && u.setItem("een_hostname", a.value), o.value !== 443 && u.setItem("een_port", String(o.value)), c.value && u.setItem("een_userProfile", JSON.stringify(c.value));
162
- } catch (u) {
163
- s("Failed to save to storage:", u instanceof Error ? u.message : String(u));
160
+ const d = V();
161
+ e.value && d.setItem("een_token", e.value), n.value && d.setItem("een_tokenExpiration", String(n.value)), t.value && d.setItem("een_refreshTokenMarker", t.value), r.value && d.setItem("een_sessionId", r.value), a.value && d.setItem("een_hostname", a.value), o.value !== 443 && d.setItem("een_port", String(o.value)), c.value && d.setItem("een_userProfile", JSON.stringify(c.value));
162
+ } catch (d) {
163
+ s("Failed to save to storage:", d instanceof Error ? d.message : String(d));
164
164
  }
165
165
  }
166
- function se() {
166
+ function le() {
167
167
  try {
168
- const u = x();
169
- e.value = u.getItem("een_token");
170
- const h = u.getItem("een_tokenExpiration");
171
- n.value = h ? parseInt(h, 10) : null, t.value = u.getItem("een_refreshTokenMarker"), r.value = u.getItem("een_sessionId"), a.value = u.getItem("een_hostname");
172
- const k = u.getItem("een_port");
168
+ const d = V();
169
+ e.value = d.getItem("een_token");
170
+ const g = d.getItem("een_tokenExpiration");
171
+ n.value = g ? parseInt(g, 10) : null, t.value = d.getItem("een_refreshTokenMarker"), r.value = d.getItem("een_sessionId"), a.value = d.getItem("een_hostname");
172
+ const k = d.getItem("een_port");
173
173
  o.value = k ? parseInt(k, 10) : 443;
174
- const j = u.getItem("een_userProfile");
175
- c.value = j ? JSON.parse(j) : null;
176
- } catch (u) {
177
- s("Failed to load from storage:", u instanceof Error ? u.message : String(u));
174
+ const q = d.getItem("een_userProfile");
175
+ c.value = q ? JSON.parse(q) : null;
176
+ } catch (d) {
177
+ s("Failed to load from storage:", d instanceof Error ? d.message : String(d));
178
178
  }
179
179
  }
180
- function ue() {
180
+ function fe() {
181
181
  try {
182
- const u = x();
183
- u.removeItem("een_token"), u.removeItem("een_tokenExpiration"), u.removeItem("een_refreshTokenMarker"), u.removeItem("een_sessionId"), u.removeItem("een_hostname"), u.removeItem("een_port"), u.removeItem("een_userProfile");
184
- } catch (u) {
185
- s("Failed to clear storage:", u instanceof Error ? u.message : String(u));
182
+ const d = V();
183
+ d.removeItem("een_token"), d.removeItem("een_tokenExpiration"), d.removeItem("een_refreshTokenMarker"), d.removeItem("een_sessionId"), d.removeItem("een_hostname"), d.removeItem("een_port"), d.removeItem("een_userProfile");
184
+ } catch (d) {
185
+ s("Failed to clear storage:", d instanceof Error ? d.message : String(d));
186
186
  }
187
187
  }
188
188
  return {
@@ -194,28 +194,28 @@ const f = _e("een-auth", () => {
194
194
  hostname: a,
195
195
  port: o,
196
196
  userProfile: c,
197
- isRefreshing: g,
198
- refreshFailed: p,
197
+ isRefreshing: R,
198
+ refreshFailed: E,
199
199
  refreshFailedMessage: _,
200
200
  // Computed
201
201
  isAuthenticated: S,
202
- baseUrl: v,
203
- isTokenExpired: R,
204
- tokenExpiresIn: P,
202
+ baseUrl: $,
203
+ isTokenExpired: p,
204
+ tokenExpiresIn: H,
205
205
  // Actions
206
- setToken: H,
206
+ setToken: z,
207
207
  setRefreshTokenMarker: N,
208
208
  setSessionId: y,
209
- setBaseUrl: O,
209
+ setBaseUrl: D,
210
210
  setUserProfile: T,
211
- setupAutoRefresh: z,
212
- clearRefreshFailed: ae,
213
- logout: J,
214
- initialize: ce
211
+ setupAutoRefresh: Q,
212
+ clearRefreshFailed: ue,
213
+ logout: Z,
214
+ initialize: de
215
215
  };
216
- }), Te = "https://auth.eagleeyenetworks.com/oauth2/authorize";
217
- function Ie() {
218
- const e = Ee();
216
+ }), ye = "https://auth.eagleeyenetworks.com/oauth2/authorize";
217
+ function Se() {
218
+ const e = Ie();
219
219
  if (!e)
220
220
  throw new Error("Client ID not configured. Call initEenToolkit() or set VITE_EEN_CLIENT_ID");
221
221
  const n = crypto.randomUUID();
@@ -227,18 +227,18 @@ function Ie() {
227
227
  client_id: e,
228
228
  response_type: "code",
229
229
  scope: "vms.all",
230
- redirect_uri: Z(),
230
+ redirect_uri: ne(),
231
231
  state: n
232
232
  });
233
- return s("Generated auth URL with state:", n), `${Te}?${t.toString()}`;
233
+ return s("Generated auth URL with state:", n), `${ye}?${t.toString()}`;
234
234
  }
235
- async function ee(e) {
236
- const n = K();
235
+ async function ie(e) {
236
+ const n = M();
237
237
  if (!n)
238
238
  return i("AUTH_FAILED", "Proxy URL not configured. Call initEenToolkit() or set VITE_PROXY_URL");
239
239
  const t = new URLSearchParams({
240
240
  code: e,
241
- redirect_uri: Z()
241
+ redirect_uri: ne()
242
242
  });
243
243
  try {
244
244
  const r = await fetch(`${n}/proxy/getAccessToken?${t.toString()}`, {
@@ -258,8 +258,8 @@ async function ee(e) {
258
258
  return i("NETWORK_ERROR", `Failed to exchange code: ${String(r)}`);
259
259
  }
260
260
  }
261
- async function Ue() {
262
- const e = K();
261
+ async function $e() {
262
+ const e = M();
263
263
  if (!e)
264
264
  return i("AUTH_FAILED", "Proxy URL not configured");
265
265
  const n = f();
@@ -283,8 +283,8 @@ async function Ue() {
283
283
  return i("NETWORK_ERROR", `Failed to refresh token: ${String(t)}`);
284
284
  }
285
285
  }
286
- async function ye() {
287
- const e = K();
286
+ async function ve() {
287
+ const e = M();
288
288
  if (!e)
289
289
  return i("AUTH_FAILED", "Proxy URL not configured");
290
290
  const n = f();
@@ -307,7 +307,7 @@ async function ye() {
307
307
  return n.logout(), i("NETWORK_ERROR", `Failed to revoke token: ${String(t)}`);
308
308
  }
309
309
  }
310
- async function Se(e, n) {
310
+ async function De(e, n) {
311
311
  let t = null;
312
312
  try {
313
313
  t = sessionStorage.getItem("een_oauth_state"), sessionStorage.removeItem("een_oauth_state");
@@ -315,16 +315,16 @@ async function Se(e, n) {
315
315
  }
316
316
  if (!t)
317
317
  return i("AUTH_FAILED", "No OAuth state found. Please restart the login process.");
318
- if (!ve(n, t))
318
+ if (!Oe(n, t))
319
319
  return i("AUTH_FAILED", "Invalid OAuth state. Possible CSRF attack.");
320
320
  s("State validated, exchanging code for token");
321
- const r = await ee(e);
321
+ const r = await ie(e);
322
322
  if (r.error)
323
323
  return r;
324
324
  const a = f(), o = r.data;
325
325
  return a.setToken(o.accessToken, o.expiresIn), a.setRefreshTokenMarker("present"), a.setSessionId(o.sessionId), a.setBaseUrl(o.httpsBaseUrl), s("Auth callback complete, user:", o.userEmail), l(o);
326
326
  }
327
- function ve(e, n) {
327
+ function Oe(e, n) {
328
328
  if (e.length !== n.length)
329
329
  return !1;
330
330
  let t = 0;
@@ -332,15 +332,15 @@ function ve(e, n) {
332
332
  t |= e.charCodeAt(r) ^ n.charCodeAt(r);
333
333
  return t === 0;
334
334
  }
335
- const $e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
335
+ const ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
336
336
  __proto__: null,
337
- getAccessToken: ee,
338
- getAuthUrl: Ie,
339
- handleAuthCallback: Se,
340
- refreshToken: Ue,
341
- revokeToken: ye
337
+ getAccessToken: ie,
338
+ getAuthUrl: Se,
339
+ handleAuthCallback: De,
340
+ refreshToken: $e,
341
+ revokeToken: ve
342
342
  }, Symbol.toStringTag, { value: "Module" }));
343
- async function me() {
343
+ async function ze() {
344
344
  const e = f();
345
345
  if (!e.isAuthenticated)
346
346
  return i("AUTH_REQUIRED", "Authentication required");
@@ -357,14 +357,14 @@ async function me() {
357
357
  }
358
358
  });
359
359
  if (!t.ok)
360
- return M(t);
360
+ return G(t);
361
361
  const r = await t.json();
362
362
  return s("Current user fetched:", r.email), e.setUserProfile(r), l(r);
363
363
  } catch (t) {
364
364
  return i("NETWORK_ERROR", `Failed to fetch current user: ${String(t)}`);
365
365
  }
366
366
  }
367
- async function Be(e) {
367
+ async function Qe(e) {
368
368
  const n = f();
369
369
  if (!n.isAuthenticated)
370
370
  return i("AUTH_REQUIRED", "Authentication required");
@@ -383,14 +383,14 @@ async function Be(e) {
383
383
  }
384
384
  });
385
385
  if (!o.ok)
386
- return M(o);
386
+ return G(o);
387
387
  const c = await o.json();
388
388
  return s("Users fetched:", c.results?.length ?? 0, "users"), l(c);
389
389
  } catch (o) {
390
390
  return i("NETWORK_ERROR", `Failed to fetch users: ${String(o)}`);
391
391
  }
392
392
  }
393
- async function Pe(e, n) {
393
+ async function Ce(e, n) {
394
394
  const t = f();
395
395
  if (!t.isAuthenticated)
396
396
  return i("AUTH_REQUIRED", "Authentication required");
@@ -411,14 +411,14 @@ async function Pe(e, n) {
411
411
  }
412
412
  });
413
413
  if (!c.ok)
414
- return M(c);
415
- const d = await c.json();
416
- return s("User fetched:", d.email), l(d);
414
+ return G(c);
415
+ const u = await c.json();
416
+ return s("User fetched:", u.email), l(u);
417
417
  } catch (c) {
418
418
  return i("NETWORK_ERROR", `Failed to fetch user: ${String(c)}`);
419
419
  }
420
420
  }
421
- async function M(e) {
421
+ async function G(e) {
422
422
  const n = e.status;
423
423
  let t;
424
424
  try {
@@ -440,7 +440,7 @@ async function M(e) {
440
440
  return i("API_ERROR", `API error: ${t}`, n);
441
441
  }
442
442
  }
443
- async function He(e) {
443
+ async function xe(e) {
444
444
  const n = f();
445
445
  if (!n.isAuthenticated)
446
446
  return i("AUTH_REQUIRED", "Authentication required");
@@ -459,14 +459,14 @@ async function He(e) {
459
459
  }
460
460
  });
461
461
  if (!o.ok)
462
- return te(o);
462
+ return re(o);
463
463
  const c = await o.json();
464
464
  return s("Cameras fetched:", c.results?.length ?? 0, "cameras"), l(c);
465
465
  } catch (o) {
466
466
  return i("NETWORK_ERROR", `Failed to fetch cameras: ${String(o)}`);
467
467
  }
468
468
  }
469
- async function ze(e, n) {
469
+ async function Ve(e, n) {
470
470
  const t = f();
471
471
  if (!t.isAuthenticated)
472
472
  return i("AUTH_REQUIRED", "Authentication required");
@@ -487,14 +487,14 @@ async function ze(e, n) {
487
487
  }
488
488
  });
489
489
  if (!c.ok)
490
- return te(c);
491
- const d = await c.json();
492
- return s("Camera fetched:", d.name), l(d);
490
+ return re(c);
491
+ const u = await c.json();
492
+ return s("Camera fetched:", u.name), l(u);
493
493
  } catch (c) {
494
494
  return i("NETWORK_ERROR", `Failed to fetch camera: ${String(c)}`);
495
495
  }
496
496
  }
497
- async function te(e) {
497
+ async function re(e) {
498
498
  const n = e.status;
499
499
  let t;
500
500
  try {
@@ -516,7 +516,7 @@ async function te(e) {
516
516
  return i("API_ERROR", `API error: ${t}`, n);
517
517
  }
518
518
  }
519
- async function Qe(e) {
519
+ async function We(e) {
520
520
  const n = f();
521
521
  if (!n.isAuthenticated)
522
522
  return i("AUTH_REQUIRED", "Authentication required");
@@ -535,14 +535,14 @@ async function Qe(e) {
535
535
  }
536
536
  });
537
537
  if (!o.ok)
538
- return ne(o);
538
+ return oe(o);
539
539
  const c = await o.json();
540
540
  return s("Bridges fetched:", c.results?.length ?? 0, "bridges"), l(c);
541
541
  } catch (o) {
542
542
  return i("NETWORK_ERROR", `Failed to fetch bridges: ${String(o)}`);
543
543
  }
544
544
  }
545
- async function Ce(e, n) {
545
+ async function Ke(e, n) {
546
546
  const t = f();
547
547
  if (!t.isAuthenticated)
548
548
  return i("AUTH_REQUIRED", "Authentication required");
@@ -563,14 +563,14 @@ async function Ce(e, n) {
563
563
  }
564
564
  });
565
565
  if (!c.ok)
566
- return ne(c);
567
- const d = await c.json();
568
- return s("Bridge fetched:", d.name), l(d);
566
+ return oe(c);
567
+ const u = await c.json();
568
+ return s("Bridge fetched:", u.name), l(u);
569
569
  } catch (c) {
570
570
  return i("NETWORK_ERROR", `Failed to fetch bridge: ${String(c)}`);
571
571
  }
572
572
  }
573
- async function ne(e) {
573
+ async function oe(e) {
574
574
  const n = e.status;
575
575
  let t;
576
576
  try {
@@ -592,7 +592,7 @@ async function ne(e) {
592
592
  return i("API_ERROR", `API error: ${t}`, n);
593
593
  }
594
594
  }
595
- async function xe(e) {
595
+ async function Me(e) {
596
596
  const n = f();
597
597
  if (!n.isAuthenticated)
598
598
  return i("AUTH_REQUIRED", "Authentication required");
@@ -618,7 +618,7 @@ async function xe(e) {
618
618
  return i("NETWORK_ERROR", `Failed to fetch layouts: ${String(o)}`);
619
619
  }
620
620
  }
621
- async function Ve(e, n) {
621
+ async function Ge(e, n) {
622
622
  const t = f();
623
623
  if (!t.isAuthenticated)
624
624
  return i("AUTH_REQUIRED", "Authentication required");
@@ -640,13 +640,13 @@ async function Ve(e, n) {
640
640
  });
641
641
  if (!c.ok)
642
642
  return w(c);
643
- const d = await c.json();
644
- return s("Layout fetched:", d.name), l(d);
643
+ const u = await c.json();
644
+ return s("Layout fetched:", u.name), l(u);
645
645
  } catch (c) {
646
646
  return i("NETWORK_ERROR", `Failed to fetch layout: ${String(c)}`);
647
647
  }
648
648
  }
649
- async function We(e) {
649
+ async function Je(e) {
650
650
  const n = f();
651
651
  if (!n.isAuthenticated)
652
652
  return i("AUTH_REQUIRED", "Authentication required");
@@ -681,7 +681,7 @@ async function We(e) {
681
681
  return i("NETWORK_ERROR", `Failed to create layout: ${String(a)}`);
682
682
  }
683
683
  }
684
- async function Ke(e, n) {
684
+ async function Xe(e, n) {
685
685
  const t = f();
686
686
  if (!t.isAuthenticated)
687
687
  return i("AUTH_REQUIRED", "Authentication required");
@@ -710,7 +710,7 @@ async function Ke(e, n) {
710
710
  return i("NETWORK_ERROR", `Failed to update layout: ${String(o)}`);
711
711
  }
712
712
  }
713
- async function Me(e) {
713
+ async function Ye(e) {
714
714
  const n = f();
715
715
  if (!n.isAuthenticated)
716
716
  return i("AUTH_REQUIRED", "Authentication required");
@@ -757,24 +757,24 @@ async function w(e) {
757
757
  return i("API_ERROR", `API error: ${t}`, n);
758
758
  }
759
759
  }
760
- const Oe = 3e4;
761
- function L(e = Oe) {
760
+ const be = 3e4;
761
+ function j(e = be) {
762
762
  const n = new AbortController(), t = setTimeout(() => n.abort(), e);
763
763
  return { controller: n, timeoutId: t };
764
764
  }
765
- function ie(e) {
765
+ function ae(e) {
766
766
  const n = new Uint8Array(e), t = 8192, r = [];
767
767
  for (let o = 0; o < n.byteLength; o += t) {
768
768
  const c = n.subarray(o, Math.min(o + t, n.byteLength));
769
- let d = "";
770
- for (let g = 0; g < c.length; g++)
771
- d += String.fromCharCode(c[g]);
772
- r.push(d);
769
+ let u = "";
770
+ for (let R = 0; R < c.length; R++)
771
+ u += String.fromCharCode(c[R]);
772
+ r.push(u);
773
773
  }
774
774
  const a = r.join("");
775
775
  return typeof btoa == "function" ? btoa(a) : Buffer.from(a, "binary").toString("base64");
776
776
  }
777
- async function Ge(e) {
777
+ async function Ze(e) {
778
778
  const n = f();
779
779
  if (!n.isAuthenticated)
780
780
  return i("AUTH_REQUIRED", "Authentication required");
@@ -792,7 +792,7 @@ async function Ge(e) {
792
792
  t.append("deviceId", e.deviceId), t.append("type", e.type), t.append("mediaType", e.mediaType), t.append("startTimestamp__gte", e.startTimestamp), e.endTimestamp && t.append("endTimestamp__lte", e.endTimestamp), typeof e.coalesce == "boolean" && t.append("coalesce", String(e.coalesce)), e.include && e.include.length > 0 && t.append("include", e.include.join(",")), e.pageToken && t.append("pageToken", e.pageToken), typeof e.pageSize == "number" && t.append("pageSize", String(e.pageSize));
793
793
  const r = `${n.baseUrl}/api/v3.0/media?${t.toString()}`;
794
794
  s("Fetching media intervals:", r);
795
- const { controller: a, timeoutId: o } = L();
795
+ const { controller: a, timeoutId: o } = j();
796
796
  try {
797
797
  const c = await fetch(r, {
798
798
  method: "GET",
@@ -803,16 +803,16 @@ async function Ge(e) {
803
803
  signal: a.signal
804
804
  });
805
805
  if (!c.ok)
806
- return F(c);
807
- const d = await c.json();
808
- return s("Media intervals fetched:", d.results?.length ?? 0, "intervals"), l(d);
806
+ return m(c);
807
+ const u = await c.json();
808
+ return s("Media intervals fetched:", u.results?.length ?? 0, "intervals"), l(u);
809
809
  } catch (c) {
810
810
  return c instanceof Error && c.name === "AbortError" ? i("NETWORK_ERROR", "Request timed out") : i("NETWORK_ERROR", `Failed to fetch media intervals: ${String(c)}`);
811
811
  } finally {
812
812
  clearTimeout(o);
813
813
  }
814
814
  }
815
- async function Je(e) {
815
+ async function et(e) {
816
816
  const n = f();
817
817
  if (!n.isAuthenticated)
818
818
  return i("AUTH_REQUIRED", "Authentication required");
@@ -824,31 +824,31 @@ async function Je(e) {
824
824
  r.append("deviceId", e.deviceId), r.append("type", t);
825
825
  const a = `${n.baseUrl}/api/v3.0/media/liveImage.jpeg?${r.toString()}`;
826
826
  s("Fetching live image:", a);
827
- const { controller: o, timeoutId: c } = L();
827
+ const { controller: o, timeoutId: c } = j();
828
828
  try {
829
- const d = await fetch(a, {
829
+ const u = await fetch(a, {
830
830
  method: "GET",
831
831
  headers: {
832
832
  Accept: "image/jpeg",
833
833
  Authorization: `Bearer ${n.token}`
834
834
  },
835
835
  signal: o.signal
836
- }), g = d.headers.get("X-Een-Timestamp"), A = d.headers.get("X-Een-PrevToken");
837
- if (!d.ok)
838
- return F(d);
839
- const p = await d.arrayBuffer(), S = `data:image/jpeg;base64,${ie(p)}`;
840
- return s("Live image fetched, timestamp:", g), l({
836
+ }), R = u.headers.get("X-Een-Timestamp"), h = u.headers.get("X-Een-PrevToken");
837
+ if (!u.ok)
838
+ return m(u);
839
+ const E = await u.arrayBuffer(), S = `data:image/jpeg;base64,${ae(E)}`;
840
+ return s("Live image fetched, timestamp:", R), l({
841
841
  imageData: S,
842
- timestamp: g,
843
- prevToken: A
842
+ timestamp: R,
843
+ prevToken: h
844
844
  });
845
- } catch (d) {
846
- return d instanceof Error && d.name === "AbortError" ? i("NETWORK_ERROR", "Request timed out") : i("NETWORK_ERROR", `Failed to fetch live image: ${String(d)}`);
845
+ } catch (u) {
846
+ return u instanceof Error && u.name === "AbortError" ? i("NETWORK_ERROR", "Request timed out") : i("NETWORK_ERROR", `Failed to fetch live image: ${String(u)}`);
847
847
  } finally {
848
848
  clearTimeout(c);
849
849
  }
850
850
  }
851
- async function Xe(e) {
851
+ async function tt(e) {
852
852
  const n = f();
853
853
  if (!n.isAuthenticated)
854
854
  return i("AUTH_REQUIRED", "Authentication required");
@@ -864,7 +864,7 @@ async function Xe(e) {
864
864
  e.deviceId && t.append("deviceId", e.deviceId), e.pageToken && t.append("pageToken", e.pageToken), e.type && t.append("type", e.type), e.timestamp__lt && t.append("timestamp__lt", e.timestamp__lt), e.timestamp__lte && t.append("timestamp__lte", e.timestamp__lte), e.timestamp && t.append("timestamp", e.timestamp), e.timestamp__gte && t.append("timestamp__gte", e.timestamp__gte), e.timestamp__gt && t.append("timestamp__gt", e.timestamp__gt), e.overlayId__in && e.overlayId__in.length > 0 && t.append("overlayId__in", e.overlayId__in.join(",")), e.include && e.include.length > 0 && t.append("include", e.include.join(",")), typeof e.targetWidth == "number" && t.append("targetWidth", String(e.targetWidth)), typeof e.targetHeight == "number" && t.append("targetHeight", String(e.targetHeight));
865
865
  const r = `${n.baseUrl}/api/v3.0/media/recordedImage.jpeg?${t.toString()}`;
866
866
  s("Fetching recorded image:", r);
867
- const { controller: a, timeoutId: o } = L();
867
+ const { controller: a, timeoutId: o } = j();
868
868
  try {
869
869
  const c = await fetch(r, {
870
870
  method: "GET",
@@ -873,16 +873,16 @@ async function Xe(e) {
873
873
  Authorization: `Bearer ${n.token}`
874
874
  },
875
875
  signal: a.signal
876
- }), d = c.headers.get("X-Een-Timestamp"), g = c.headers.get("X-Een-NextToken"), A = c.headers.get("X-Een-PrevToken"), p = c.headers.get("X-Een-OverlaySvg");
876
+ }), u = c.headers.get("X-Een-Timestamp"), R = c.headers.get("X-Een-NextToken"), h = c.headers.get("X-Een-PrevToken"), E = c.headers.get("X-Een-OverlaySvg");
877
877
  if (!c.ok)
878
- return F(c);
879
- const _ = await c.arrayBuffer(), v = `data:image/jpeg;base64,${ie(_)}`;
880
- return s("Recorded image fetched, timestamp:", d), l({
881
- imageData: v,
882
- timestamp: d,
883
- nextToken: g,
884
- prevToken: A,
885
- overlaySvg: p
878
+ return m(c);
879
+ const _ = await c.arrayBuffer(), $ = `data:image/jpeg;base64,${ae(_)}`;
880
+ return s("Recorded image fetched, timestamp:", u), l({
881
+ imageData: $,
882
+ timestamp: u,
883
+ nextToken: R,
884
+ prevToken: h,
885
+ overlaySvg: E
886
886
  });
887
887
  } catch (c) {
888
888
  return c instanceof Error && c.name === "AbortError" ? i("NETWORK_ERROR", "Request timed out") : i("NETWORK_ERROR", `Failed to fetch recorded image: ${String(c)}`);
@@ -890,7 +890,7 @@ async function Xe(e) {
890
890
  clearTimeout(o);
891
891
  }
892
892
  }
893
- async function F(e) {
893
+ async function m(e) {
894
894
  const n = e.status;
895
895
  let t;
896
896
  try {
@@ -914,7 +914,7 @@ async function F(e) {
914
914
  return i("API_ERROR", `API error: ${t}`, n);
915
915
  }
916
916
  }
917
- async function De() {
917
+ async function we() {
918
918
  const e = f();
919
919
  if (!e.isAuthenticated)
920
920
  return i("AUTH_REQUIRED", "Authentication required");
@@ -922,7 +922,7 @@ async function De() {
922
922
  return i("AUTH_REQUIRED", "Base URL not configured");
923
923
  const n = `${e.baseUrl}/api/v3.0/media/session`;
924
924
  s("Fetching media session:", n);
925
- const { controller: t, timeoutId: r } = L();
925
+ const { controller: t, timeoutId: r } = j();
926
926
  try {
927
927
  const a = await fetch(n, {
928
928
  method: "GET",
@@ -933,7 +933,7 @@ async function De() {
933
933
  signal: t.signal
934
934
  });
935
935
  if (!a.ok)
936
- return F(a);
936
+ return m(a);
937
937
  const o = await a.json();
938
938
  return s("Media session URL received:", o.url), l(o);
939
939
  } catch (a) {
@@ -942,11 +942,11 @@ async function De() {
942
942
  clearTimeout(r);
943
943
  }
944
944
  }
945
- async function Ye() {
945
+ async function nt() {
946
946
  const e = f();
947
947
  if (!e.isAuthenticated)
948
948
  return i("AUTH_REQUIRED", "Authentication required");
949
- const n = await De();
949
+ const n = await we();
950
950
  if (n.error)
951
951
  return i(
952
952
  n.error.code,
@@ -957,7 +957,7 @@ async function Ye() {
957
957
  return i("API_ERROR", "No session URL returned from media session endpoint");
958
958
  const t = n.data.url;
959
959
  s("Calling session URL to set cookie:", t);
960
- const { controller: r, timeoutId: a } = L();
960
+ const { controller: r, timeoutId: a } = j();
961
961
  try {
962
962
  const o = await fetch(t, {
963
963
  method: "GET",
@@ -971,14 +971,14 @@ async function Ye() {
971
971
  });
972
972
  if (!o.ok && o.status !== 204) {
973
973
  const c = o.status;
974
- let d;
974
+ let u;
975
975
  try {
976
- const g = await o.json();
977
- d = g.message ?? g.error ?? o.statusText;
976
+ const R = await o.json();
977
+ u = R.message ?? R.error ?? o.statusText;
978
978
  } catch {
979
- d = o.statusText || "Unknown error";
979
+ u = o.statusText || "Unknown error";
980
980
  }
981
- return i("API_ERROR", `Failed to set media session cookie: ${d}`, c);
981
+ return i("API_ERROR", `Failed to set media session cookie: ${u}`, c);
982
982
  }
983
983
  return s("Media session cookie set successfully"), l({
984
984
  success: !0,
@@ -990,7 +990,7 @@ async function Ye() {
990
990
  clearTimeout(a);
991
991
  }
992
992
  }
993
- async function Ze(e) {
993
+ async function it(e) {
994
994
  const n = f();
995
995
  if (!n.isAuthenticated)
996
996
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1010,14 +1010,14 @@ async function Ze(e) {
1010
1010
  signal: e?.signal
1011
1011
  });
1012
1012
  if (!o.ok)
1013
- return ke(o);
1013
+ return je(o);
1014
1014
  const c = await o.json();
1015
1015
  return s("Feeds fetched:", c.results?.length ?? 0, "feeds"), l(c);
1016
1016
  } catch (o) {
1017
1017
  return i("NETWORK_ERROR", `Failed to fetch feeds: ${String(o)}`);
1018
1018
  }
1019
1019
  }
1020
- async function ke(e) {
1020
+ async function je(e) {
1021
1021
  const n = e.status;
1022
1022
  let t;
1023
1023
  try {
@@ -1041,7 +1041,7 @@ async function ke(e) {
1041
1041
  return i("API_ERROR", t || e.statusText || "API error", n);
1042
1042
  }
1043
1043
  }
1044
- async function et(e) {
1044
+ async function rt(e) {
1045
1045
  const n = f();
1046
1046
  if (!n.isAuthenticated)
1047
1047
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1066,14 +1066,14 @@ async function et(e) {
1066
1066
  }
1067
1067
  });
1068
1068
  if (!o.ok)
1069
- return m(o);
1069
+ return B(o);
1070
1070
  const c = await o.json();
1071
1071
  return s("Events fetched:", c.results?.length ?? 0, "events"), l(c);
1072
1072
  } catch (o) {
1073
1073
  return i("NETWORK_ERROR", `Failed to fetch events: ${String(o)}`);
1074
1074
  }
1075
1075
  }
1076
- async function tt(e, n) {
1076
+ async function ot(e, n) {
1077
1077
  const t = f();
1078
1078
  if (!t.isAuthenticated)
1079
1079
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1094,14 +1094,14 @@ async function tt(e, n) {
1094
1094
  }
1095
1095
  });
1096
1096
  if (!c.ok)
1097
- return m(c);
1098
- const d = await c.json();
1099
- return s("Event fetched:", d.id), l(d);
1097
+ return B(c);
1098
+ const u = await c.json();
1099
+ return s("Event fetched:", u.id), l(u);
1100
1100
  } catch (c) {
1101
1101
  return i("NETWORK_ERROR", `Failed to fetch event: ${String(c)}`);
1102
1102
  }
1103
1103
  }
1104
- async function nt(e) {
1104
+ async function at(e) {
1105
1105
  const n = f();
1106
1106
  if (!n.isAuthenticated)
1107
1107
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1120,14 +1120,14 @@ async function nt(e) {
1120
1120
  }
1121
1121
  });
1122
1122
  if (!o.ok)
1123
- return m(o);
1123
+ return B(o);
1124
1124
  const c = await o.json();
1125
1125
  return s("Event types fetched:", c.results?.length ?? 0, "types"), l(c);
1126
1126
  } catch (o) {
1127
1127
  return i("NETWORK_ERROR", `Failed to fetch event types: ${String(o)}`);
1128
1128
  }
1129
1129
  }
1130
- async function it(e) {
1130
+ async function ct(e) {
1131
1131
  const n = f();
1132
1132
  if (!n.isAuthenticated)
1133
1133
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1148,14 +1148,14 @@ async function it(e) {
1148
1148
  }
1149
1149
  });
1150
1150
  if (!o.ok)
1151
- return m(o);
1151
+ return B(o);
1152
1152
  const c = await o.json();
1153
1153
  return s("Event field values fetched:", c.type?.length ?? 0, "types"), l(c);
1154
1154
  } catch (o) {
1155
1155
  return i("NETWORK_ERROR", `Failed to fetch event field values: ${String(o)}`);
1156
1156
  }
1157
1157
  }
1158
- async function m(e) {
1158
+ async function B(e) {
1159
1159
  const n = e.status;
1160
1160
  let t;
1161
1161
  try {
@@ -1177,7 +1177,7 @@ async function m(e) {
1177
1177
  return i("API_ERROR", `API error: ${t}`, n);
1178
1178
  }
1179
1179
  }
1180
- async function rt(e) {
1180
+ async function st(e) {
1181
1181
  const n = f();
1182
1182
  if (!n.isAuthenticated)
1183
1183
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1200,14 +1200,14 @@ async function rt(e) {
1200
1200
  }
1201
1201
  });
1202
1202
  if (!o.ok)
1203
- return be(o);
1203
+ return Le(o);
1204
1204
  const c = await o.json();
1205
1205
  return s("Event metrics fetched:", c.length, "metrics"), l(c);
1206
1206
  } catch (o) {
1207
1207
  return i("NETWORK_ERROR", `Failed to fetch event metrics: ${String(o)}`);
1208
1208
  }
1209
1209
  }
1210
- async function be(e) {
1210
+ async function Le(e) {
1211
1211
  const n = e.status;
1212
1212
  let t;
1213
1213
  try {
@@ -1229,7 +1229,7 @@ async function be(e) {
1229
1229
  return i("API_ERROR", `API error: ${t}`, n);
1230
1230
  }
1231
1231
  }
1232
- async function ot(e) {
1232
+ async function ut(e) {
1233
1233
  const n = f();
1234
1234
  if (!n.isAuthenticated)
1235
1235
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1248,14 +1248,14 @@ async function ot(e) {
1248
1248
  }
1249
1249
  });
1250
1250
  if (!o.ok)
1251
- return G(o);
1251
+ return J(o);
1252
1252
  const c = await o.json();
1253
1253
  return s("Alerts fetched:", c.results?.length ?? 0, "alerts"), l(c);
1254
1254
  } catch (o) {
1255
1255
  return i("NETWORK_ERROR", `Failed to fetch alerts: ${String(o)}`);
1256
1256
  }
1257
1257
  }
1258
- async function at(e, n) {
1258
+ async function dt(e, n) {
1259
1259
  const t = f();
1260
1260
  if (!t.isAuthenticated)
1261
1261
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1276,14 +1276,14 @@ async function at(e, n) {
1276
1276
  }
1277
1277
  });
1278
1278
  if (!c.ok)
1279
- return G(c);
1280
- const d = await c.json();
1281
- return s("Alert fetched:", d.id), l(d);
1279
+ return J(c);
1280
+ const u = await c.json();
1281
+ return s("Alert fetched:", u.id), l(u);
1282
1282
  } catch (c) {
1283
1283
  return i("NETWORK_ERROR", `Failed to fetch alert: ${String(c)}`);
1284
1284
  }
1285
1285
  }
1286
- async function ct(e) {
1286
+ async function lt(e) {
1287
1287
  const n = f();
1288
1288
  if (!n.isAuthenticated)
1289
1289
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1302,14 +1302,14 @@ async function ct(e) {
1302
1302
  }
1303
1303
  });
1304
1304
  if (!o.ok)
1305
- return G(o);
1305
+ return J(o);
1306
1306
  const c = await o.json();
1307
1307
  return s("Alert types fetched:", c.results?.length ?? 0, "types"), l(c);
1308
1308
  } catch (o) {
1309
1309
  return i("NETWORK_ERROR", `Failed to fetch alert types: ${String(o)}`);
1310
1310
  }
1311
1311
  }
1312
- async function G(e) {
1312
+ async function J(e) {
1313
1313
  const n = e.status;
1314
1314
  let t;
1315
1315
  try {
@@ -1331,7 +1331,7 @@ async function G(e) {
1331
1331
  return i("API_ERROR", `API error: ${t}`, n);
1332
1332
  }
1333
1333
  }
1334
- async function st(e) {
1334
+ async function ft(e) {
1335
1335
  const n = f();
1336
1336
  if (!n.isAuthenticated)
1337
1337
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1350,14 +1350,14 @@ async function st(e) {
1350
1350
  }
1351
1351
  });
1352
1352
  if (!o.ok)
1353
- return re(o);
1353
+ return ce(o);
1354
1354
  const c = await o.json();
1355
1355
  return s("Notifications fetched:", c.results?.length ?? 0, "notifications"), l(c);
1356
1356
  } catch (o) {
1357
1357
  return i("NETWORK_ERROR", `Failed to fetch notifications: ${String(o)}`);
1358
1358
  }
1359
1359
  }
1360
- async function ut(e) {
1360
+ async function _t(e) {
1361
1361
  const n = f();
1362
1362
  if (!n.isAuthenticated)
1363
1363
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1376,14 +1376,14 @@ async function ut(e) {
1376
1376
  }
1377
1377
  });
1378
1378
  if (!r.ok)
1379
- return re(r);
1379
+ return ce(r);
1380
1380
  const a = await r.json();
1381
1381
  return s("Notification fetched:", a.id), l(a);
1382
1382
  } catch (r) {
1383
1383
  return i("NETWORK_ERROR", `Failed to fetch notification: ${String(r)}`);
1384
1384
  }
1385
1385
  }
1386
- async function re(e) {
1386
+ async function ce(e) {
1387
1387
  const n = e.status;
1388
1388
  let t;
1389
1389
  try {
@@ -1405,7 +1405,7 @@ async function re(e) {
1405
1405
  return i("API_ERROR", `API error: ${t}`, n);
1406
1406
  }
1407
1407
  }
1408
- async function dt(e) {
1408
+ async function Rt(e) {
1409
1409
  const n = f();
1410
1410
  if (!n.isAuthenticated)
1411
1411
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1424,14 +1424,14 @@ async function dt(e) {
1424
1424
  }
1425
1425
  });
1426
1426
  if (!o.ok)
1427
- return B(o);
1427
+ return P(o);
1428
1428
  const c = await o.json();
1429
1429
  return s("Event subscriptions fetched:", c.results?.length ?? 0, "subscriptions"), l(c);
1430
1430
  } catch (o) {
1431
1431
  return i("NETWORK_ERROR", `Failed to fetch event subscriptions: ${String(o)}`);
1432
1432
  }
1433
1433
  }
1434
- async function lt(e) {
1434
+ async function ht(e) {
1435
1435
  const n = f();
1436
1436
  if (!n.isAuthenticated)
1437
1437
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1450,14 +1450,14 @@ async function lt(e) {
1450
1450
  }
1451
1451
  });
1452
1452
  if (!r.ok)
1453
- return B(r);
1453
+ return P(r);
1454
1454
  const a = await r.json();
1455
1455
  return s("Event subscription fetched:", a.id), l(a);
1456
1456
  } catch (r) {
1457
1457
  return i("NETWORK_ERROR", `Failed to fetch event subscription: ${String(r)}`);
1458
1458
  }
1459
1459
  }
1460
- async function ft(e) {
1460
+ async function gt(e) {
1461
1461
  const n = f();
1462
1462
  if (!n.isAuthenticated)
1463
1463
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1486,14 +1486,14 @@ async function ft(e) {
1486
1486
  body: JSON.stringify(e)
1487
1487
  });
1488
1488
  if (!r.ok)
1489
- return B(r);
1489
+ return P(r);
1490
1490
  const a = await r.json();
1491
1491
  return s("Event subscription created:", a.id), l(a);
1492
1492
  } catch (r) {
1493
1493
  return i("NETWORK_ERROR", `Failed to create event subscription: ${String(r)}`);
1494
1494
  }
1495
1495
  }
1496
- async function _t(e) {
1496
+ async function pt(e) {
1497
1497
  const n = f();
1498
1498
  if (!n.isAuthenticated)
1499
1499
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1511,12 +1511,12 @@ async function _t(e) {
1511
1511
  Authorization: `Bearer ${n.token}`
1512
1512
  }
1513
1513
  });
1514
- return r.ok ? (s("Event subscription deleted:", e), l(void 0)) : B(r);
1514
+ return r.ok ? (s("Event subscription deleted:", e), l(void 0)) : P(r);
1515
1515
  } catch (r) {
1516
1516
  return i("NETWORK_ERROR", `Failed to delete event subscription: ${String(r)}`);
1517
1517
  }
1518
1518
  }
1519
- function ht(e, n) {
1519
+ function Et(e, n) {
1520
1520
  const t = f();
1521
1521
  if (!t.isAuthenticated)
1522
1522
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1527,7 +1527,7 @@ function ht(e, n) {
1527
1527
  try {
1528
1528
  const _ = new URL(e);
1529
1529
  if (![".eagleeyenetworks.com", ".een.cloud"].some(
1530
- (R) => _.hostname === R.substring(1) || _.hostname.endsWith(R)
1530
+ (p) => _.hostname === p.substring(1) || _.hostname.endsWith(p)
1531
1531
  ))
1532
1532
  return i("VALIDATION_ERROR", `SSE URL domain not allowed: ${_.hostname}`);
1533
1533
  } catch {
@@ -1535,14 +1535,14 @@ function ht(e, n) {
1535
1535
  }
1536
1536
  const r = 1024 * 1024;
1537
1537
  let a = "connecting", o = new AbortController(), c = !1;
1538
- const d = (_) => {
1538
+ const u = (_) => {
1539
1539
  a = _, n.onStatusChange?.(a);
1540
- }, g = () => {
1541
- c || (c = !0, s("Closing SSE connection"), o?.abort(), o = null, d("disconnected"));
1540
+ }, R = () => {
1541
+ c || (c = !0, s("Closing SSE connection"), o?.abort(), o = null, u("disconnected"));
1542
1542
  };
1543
1543
  return (async () => {
1544
1544
  if (!(c || !o)) {
1545
- d("connecting"), s("Connecting to SSE:", e);
1545
+ u("connecting"), s("Connecting to SSE:", e);
1546
1546
  try {
1547
1547
  const _ = await fetch(e, {
1548
1548
  method: "GET",
@@ -1556,29 +1556,29 @@ function ht(e, n) {
1556
1556
  throw new Error(`HTTP ${_.status}: ${_.statusText}`);
1557
1557
  if (!_.body)
1558
1558
  throw new Error("Response body is not available");
1559
- d("connected"), s("SSE connected");
1560
- const S = _.body.getReader(), v = new TextDecoder();
1561
- let R = "";
1559
+ u("connected"), s("SSE connected");
1560
+ const S = _.body.getReader(), $ = new TextDecoder();
1561
+ let p = "";
1562
1562
  for (; !c; ) {
1563
- const { done: P, value: H } = await S.read();
1564
- if (P) {
1563
+ const { done: H, value: z } = await S.read();
1564
+ if (H) {
1565
1565
  s("SSE stream ended");
1566
1566
  break;
1567
1567
  }
1568
- if (R += v.decode(H, { stream: !0 }), R.length > r) {
1569
- s("SSE buffer exceeded maximum size, resetting"), R = "";
1568
+ if (p += $.decode(z, { stream: !0 }), p.length > r) {
1569
+ s("SSE buffer exceeded maximum size, resetting"), p = "";
1570
1570
  continue;
1571
1571
  }
1572
- const N = R.split(`
1572
+ const N = p.split(`
1573
1573
  `);
1574
- R = N.pop() || "";
1574
+ p = N.pop() || "";
1575
1575
  let y = "";
1576
- for (const O of N)
1577
- if (O.startsWith("data:")) {
1578
- const T = O.substring(5).trimStart();
1576
+ for (const D of N)
1577
+ if (D.startsWith("data:")) {
1578
+ const T = D.substring(5).trimStart();
1579
1579
  y = y ? `${y}
1580
1580
  ${T}` : T;
1581
- } else if (O === "" && y) {
1581
+ } else if (D === "" && y) {
1582
1582
  try {
1583
1583
  const T = JSON.parse(y);
1584
1584
  s("SSE event received:", T.type, T.actorId), n.onEvent(T);
@@ -1591,17 +1591,17 @@ ${T}` : T;
1591
1591
  } catch (_) {
1592
1592
  if (c || _ instanceof Error && _.name === "AbortError")
1593
1593
  return;
1594
- s("SSE error:", _), d("error"), n.onError?.(_ instanceof Error ? _ : new Error(String(_)));
1594
+ s("SSE error:", _), u("error"), n.onError?.(_ instanceof Error ? _ : new Error(String(_)));
1595
1595
  }
1596
1596
  }
1597
1597
  })(), l({
1598
- close: g,
1598
+ close: R,
1599
1599
  get status() {
1600
1600
  return a;
1601
1601
  }
1602
1602
  });
1603
1603
  }
1604
- async function B(e) {
1604
+ async function P(e) {
1605
1605
  const n = e.status;
1606
1606
  let t;
1607
1607
  try {
@@ -1623,7 +1623,7 @@ async function B(e) {
1623
1623
  return i("API_ERROR", t, n);
1624
1624
  }
1625
1625
  }
1626
- async function gt(e) {
1626
+ async function At(e) {
1627
1627
  const n = f();
1628
1628
  if (!n.isAuthenticated)
1629
1629
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1649,7 +1649,7 @@ async function gt(e) {
1649
1649
  return i("NETWORK_ERROR", `Failed to fetch event alert condition rules: ${String(o)}`);
1650
1650
  }
1651
1651
  }
1652
- async function Rt(e) {
1652
+ async function Tt(e) {
1653
1653
  const n = f();
1654
1654
  if (!n.isAuthenticated)
1655
1655
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1675,7 +1675,7 @@ async function Rt(e) {
1675
1675
  return i("NETWORK_ERROR", `Failed to fetch field values: ${String(o)}`);
1676
1676
  }
1677
1677
  }
1678
- async function pt(e) {
1678
+ async function It(e) {
1679
1679
  const n = f();
1680
1680
  if (!n.isAuthenticated)
1681
1681
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1701,7 +1701,7 @@ async function pt(e) {
1701
1701
  return i("NETWORK_ERROR", `Failed to fetch event alert condition rule: ${String(r)}`);
1702
1702
  }
1703
1703
  }
1704
- async function Et(e) {
1704
+ async function Ut(e) {
1705
1705
  const n = f();
1706
1706
  if (!n.isAuthenticated)
1707
1707
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1727,7 +1727,7 @@ async function Et(e) {
1727
1727
  return i("NETWORK_ERROR", `Failed to fetch alert condition rules: ${String(o)}`);
1728
1728
  }
1729
1729
  }
1730
- async function At(e, n) {
1730
+ async function yt(e, n) {
1731
1731
  const t = f();
1732
1732
  if (!t.isAuthenticated)
1733
1733
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1749,13 +1749,13 @@ async function At(e, n) {
1749
1749
  });
1750
1750
  if (!c.ok)
1751
1751
  return U(c);
1752
- const d = await c.json();
1753
- return s("Alert condition rule fetched:", d.id), l(d);
1752
+ const u = await c.json();
1753
+ return s("Alert condition rule fetched:", u.id), l(u);
1754
1754
  } catch (c) {
1755
1755
  return i("NETWORK_ERROR", `Failed to fetch alert condition rule: ${String(c)}`);
1756
1756
  }
1757
1757
  }
1758
- async function Tt(e) {
1758
+ async function St(e) {
1759
1759
  const n = f();
1760
1760
  if (!n.isAuthenticated)
1761
1761
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1781,7 +1781,7 @@ async function Tt(e) {
1781
1781
  return i("NETWORK_ERROR", `Failed to fetch alert action rules: ${String(o)}`);
1782
1782
  }
1783
1783
  }
1784
- async function It(e) {
1784
+ async function $t(e) {
1785
1785
  const n = f();
1786
1786
  if (!n.isAuthenticated)
1787
1787
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1807,7 +1807,7 @@ async function It(e) {
1807
1807
  return i("NETWORK_ERROR", `Failed to fetch alert action rule: ${String(r)}`);
1808
1808
  }
1809
1809
  }
1810
- async function Ut(e) {
1810
+ async function vt(e) {
1811
1811
  const n = f();
1812
1812
  if (!n.isAuthenticated)
1813
1813
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1833,7 +1833,7 @@ async function Ut(e) {
1833
1833
  return i("NETWORK_ERROR", `Failed to fetch alert actions: ${String(o)}`);
1834
1834
  }
1835
1835
  }
1836
- async function yt(e) {
1836
+ async function Dt(e) {
1837
1837
  const n = f();
1838
1838
  if (!n.isAuthenticated)
1839
1839
  return i("AUTH_REQUIRED", "Authentication required");
@@ -1881,64 +1881,527 @@ async function U(e) {
1881
1881
  return i("API_ERROR", `API error: ${t}`, n);
1882
1882
  }
1883
1883
  }
1884
+ async function Ot(e) {
1885
+ const n = f();
1886
+ if (!n.isAuthenticated)
1887
+ return i("AUTH_REQUIRED", "Authentication required");
1888
+ if (!n.baseUrl)
1889
+ return i("AUTH_REQUIRED", "Base URL not configured");
1890
+ if (!e.cameraId)
1891
+ return i("VALIDATION_ERROR", "Camera ID is required");
1892
+ if (!e.type)
1893
+ return i("VALIDATION_ERROR", "Export type is required");
1894
+ if (!e.startTimestamp)
1895
+ return i("VALIDATION_ERROR", "Start timestamp is required");
1896
+ if (!e.endTimestamp)
1897
+ return i("VALIDATION_ERROR", "End timestamp is required");
1898
+ const t = `${n.baseUrl}/api/v3.0/exports`;
1899
+ if (s("Creating export job:", t), (e.type === "timeLapse" || e.type === "bundle") && !e.playbackMultiplier)
1900
+ return i("VALIDATION_ERROR", "Playback multiplier is required for timeLapse and bundle exports");
1901
+ if (e.playbackMultiplier !== void 0 && (e.playbackMultiplier < 1 || e.playbackMultiplier > 48))
1902
+ return i("VALIDATION_ERROR", "Playback multiplier must be between 1 and 48");
1903
+ const r = {
1904
+ name: e.name || `Export-${Date.now()}`,
1905
+ directory: e.directory || "/"
1906
+ };
1907
+ e.notes && (r.notes = e.notes), e.tags && e.tags.length > 0 && (r.tags = e.tags);
1908
+ const a = {
1909
+ startTimestamp: e.startTimestamp,
1910
+ endTimestamp: e.endTimestamp
1911
+ }, o = {
1912
+ deviceId: e.cameraId,
1913
+ // API uses deviceId, not cameraId
1914
+ type: e.type,
1915
+ info: r,
1916
+ period: a
1917
+ };
1918
+ e.playbackMultiplier !== void 0 && (o.playbackMultiplier = e.playbackMultiplier), e.autoDelete !== void 0 && (o.autoDelete = e.autoDelete);
1919
+ try {
1920
+ const c = await fetch(t, {
1921
+ method: "POST",
1922
+ headers: {
1923
+ Accept: "application/json",
1924
+ "Content-Type": "application/json",
1925
+ Authorization: `Bearer ${n.token}`
1926
+ },
1927
+ body: JSON.stringify(o)
1928
+ });
1929
+ if (!c.ok)
1930
+ return Ne(c);
1931
+ const u = await c.json();
1932
+ return s("Export job created:", u.id), l(u);
1933
+ } catch (c) {
1934
+ return i("NETWORK_ERROR", `Failed to create export job: ${String(c)}`);
1935
+ }
1936
+ }
1937
+ async function Ne(e) {
1938
+ const n = e.status;
1939
+ let t;
1940
+ try {
1941
+ const r = await e.json();
1942
+ t = r.message ?? r.error ?? e.statusText;
1943
+ } catch {
1944
+ t = e.statusText || "Unknown error";
1945
+ }
1946
+ switch (n) {
1947
+ case 401:
1948
+ return i("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
1949
+ case 403:
1950
+ return i("FORBIDDEN", `Access denied: ${t}`, n);
1951
+ case 404:
1952
+ return i("NOT_FOUND", `Not found: ${t}`, n);
1953
+ case 429:
1954
+ return i("RATE_LIMITED", `Rate limited: ${t}`, n);
1955
+ default:
1956
+ return i("API_ERROR", `API error: ${t}`, n);
1957
+ }
1958
+ }
1959
+ async function kt(e) {
1960
+ const n = f();
1961
+ if (!n.isAuthenticated)
1962
+ return i("AUTH_REQUIRED", "Authentication required");
1963
+ if (!n.baseUrl)
1964
+ return i("AUTH_REQUIRED", "Base URL not configured");
1965
+ const t = new URLSearchParams();
1966
+ e?.pageSize && t.append("pageSize", String(e.pageSize)), e?.pageToken && t.append("pageToken", e.pageToken), e?.state__in && e.state__in.length > 0 && t.append("state__in", e.state__in.join(",")), e?.type && t.append("type", e.type), e?.type__in && e.type__in.length > 0 && t.append("type__in", e.type__in.join(",")), e?.createTimestamp__gte && t.append("createTimestamp__gte", e.createTimestamp__gte), e?.createTimestamp__lte && t.append("createTimestamp__lte", e.createTimestamp__lte), e?.userId && t.append("userId", e.userId), e?.sort && e.sort.length > 0 && t.append("sort", e.sort.join(","));
1967
+ const r = t.toString(), a = `${n.baseUrl}/api/v3.0/jobs${r ? `?${r}` : ""}`;
1968
+ s("Fetching jobs:", a);
1969
+ try {
1970
+ const o = await fetch(a, {
1971
+ method: "GET",
1972
+ headers: {
1973
+ Accept: "application/json",
1974
+ Authorization: `Bearer ${n.token}`
1975
+ }
1976
+ });
1977
+ if (!o.ok)
1978
+ return X(o);
1979
+ const c = await o.json();
1980
+ return s("Jobs fetched:", c.results?.length ?? 0, "jobs"), l(c);
1981
+ } catch (o) {
1982
+ return i("NETWORK_ERROR", `Failed to fetch jobs: ${String(o)}`);
1983
+ }
1984
+ }
1985
+ async function bt(e, n) {
1986
+ const t = f();
1987
+ if (!t.isAuthenticated)
1988
+ return i("AUTH_REQUIRED", "Authentication required");
1989
+ if (!t.baseUrl)
1990
+ return i("AUTH_REQUIRED", "Base URL not configured");
1991
+ if (!e)
1992
+ return i("VALIDATION_ERROR", "Job ID is required");
1993
+ const r = new URLSearchParams();
1994
+ n?.include && n.include.length > 0 && r.append("include", n.include.join(","));
1995
+ const a = r.toString(), o = `${t.baseUrl}/api/v3.0/jobs/${encodeURIComponent(e)}${a ? `?${a}` : ""}`;
1996
+ s("Fetching job:", o);
1997
+ try {
1998
+ const c = await fetch(o, {
1999
+ method: "GET",
2000
+ headers: {
2001
+ Accept: "application/json",
2002
+ Authorization: `Bearer ${t.token}`
2003
+ }
2004
+ });
2005
+ if (!c.ok)
2006
+ return X(c);
2007
+ const u = await c.json();
2008
+ return s("Job fetched:", u.arguments?.originalRequest?.name || u.id, "state:", u.state), l(u);
2009
+ } catch (c) {
2010
+ return i("NETWORK_ERROR", `Failed to fetch job: ${String(c)}`);
2011
+ }
2012
+ }
2013
+ async function wt(e) {
2014
+ const n = f();
2015
+ if (!n.isAuthenticated)
2016
+ return i("AUTH_REQUIRED", "Authentication required");
2017
+ if (!n.baseUrl)
2018
+ return i("AUTH_REQUIRED", "Base URL not configured");
2019
+ if (!e)
2020
+ return i("VALIDATION_ERROR", "Job ID is required");
2021
+ const t = `${n.baseUrl}/api/v3.0/jobs/${encodeURIComponent(e)}`;
2022
+ s("Deleting job:", t);
2023
+ try {
2024
+ const r = await fetch(t, {
2025
+ method: "DELETE",
2026
+ headers: {
2027
+ Authorization: `Bearer ${n.token}`
2028
+ }
2029
+ });
2030
+ return r.ok ? (s("Job deleted:", e), l(void 0)) : X(r);
2031
+ } catch (r) {
2032
+ return i("NETWORK_ERROR", `Failed to delete job: ${String(r)}`);
2033
+ }
2034
+ }
2035
+ async function X(e) {
2036
+ const n = e.status;
2037
+ let t;
2038
+ try {
2039
+ const r = await e.json();
2040
+ t = r.message ?? r.error ?? e.statusText;
2041
+ } catch {
2042
+ t = e.statusText || "Unknown error";
2043
+ }
2044
+ switch (n) {
2045
+ case 401:
2046
+ return i("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
2047
+ case 403:
2048
+ return i("FORBIDDEN", `Access denied: ${t}`, n);
2049
+ case 404:
2050
+ return i("NOT_FOUND", `Not found: ${t}`, n);
2051
+ case 429:
2052
+ return i("RATE_LIMITED", `Rate limited: ${t}`, n);
2053
+ default:
2054
+ return i("API_ERROR", `API error: ${t}`, n);
2055
+ }
2056
+ }
2057
+ async function jt(e) {
2058
+ const n = f();
2059
+ if (!n.isAuthenticated)
2060
+ return i("AUTH_REQUIRED", "Authentication required");
2061
+ if (!n.baseUrl)
2062
+ return i("AUTH_REQUIRED", "Base URL not configured");
2063
+ const t = new URLSearchParams();
2064
+ e?.pageSize && t.append("pageSize", String(e.pageSize)), e?.pageToken && t.append("pageToken", e.pageToken), e?.include && e.include.length > 0 && t.append("include", e.include.join(",")), e?.type__in && e.type__in.length > 0 && t.append("type__in", e.type__in.join(",")), e?.cameraId && t.append("cameraId", e.cameraId), e?.cameraId__in && e.cameraId__in.length > 0 && t.append("cameraId__in", e.cameraId__in.join(",")), e?.jobId && t.append("jobId", e.jobId), e?.createTimestamp__gte && t.append("createTimestamp__gte", e.createTimestamp__gte), e?.createTimestamp__lte && t.append("createTimestamp__lte", e.createTimestamp__lte), e?.tags__contains && e.tags__contains.length > 0 && t.append("tags__contains", e.tags__contains.join(",")), e?.q && t.append("q", e.q), e?.sort && e.sort.length > 0 && t.append("sort", e.sort.join(","));
2065
+ const r = t.toString(), a = `${n.baseUrl}/api/v3.0/files${r ? `?${r}` : ""}`;
2066
+ s("Fetching files:", a);
2067
+ try {
2068
+ const o = await fetch(a, {
2069
+ method: "GET",
2070
+ headers: {
2071
+ Accept: "application/json",
2072
+ Authorization: `Bearer ${n.token}`
2073
+ }
2074
+ });
2075
+ if (!o.ok)
2076
+ return L(o);
2077
+ const c = await o.json();
2078
+ return s("Files fetched:", c.results?.length ?? 0, "files"), l(c);
2079
+ } catch (o) {
2080
+ return i("NETWORK_ERROR", `Failed to fetch files: ${String(o)}`);
2081
+ }
2082
+ }
2083
+ async function Lt(e, n) {
2084
+ const t = f();
2085
+ if (!t.isAuthenticated)
2086
+ return i("AUTH_REQUIRED", "Authentication required");
2087
+ if (!t.baseUrl)
2088
+ return i("AUTH_REQUIRED", "Base URL not configured");
2089
+ if (!e)
2090
+ return i("VALIDATION_ERROR", "File ID is required");
2091
+ const r = new URLSearchParams();
2092
+ n?.include && n.include.length > 0 && r.append("include", n.include.join(","));
2093
+ const a = r.toString(), o = `${t.baseUrl}/api/v3.0/files/${encodeURIComponent(e)}${a ? `?${a}` : ""}`;
2094
+ s("Fetching file:", o);
2095
+ try {
2096
+ const c = await fetch(o, {
2097
+ method: "GET",
2098
+ headers: {
2099
+ Accept: "application/json",
2100
+ Authorization: `Bearer ${t.token}`
2101
+ }
2102
+ });
2103
+ if (!c.ok)
2104
+ return L(c);
2105
+ const u = await c.json();
2106
+ return s("File fetched:", u.name), l(u);
2107
+ } catch (c) {
2108
+ return i("NETWORK_ERROR", `Failed to fetch file: ${String(c)}`);
2109
+ }
2110
+ }
2111
+ async function Nt(e) {
2112
+ const n = f();
2113
+ if (!n.isAuthenticated)
2114
+ return i("AUTH_REQUIRED", "Authentication required");
2115
+ if (!n.baseUrl)
2116
+ return i("AUTH_REQUIRED", "Base URL not configured");
2117
+ if (!e.name)
2118
+ return i("VALIDATION_ERROR", "File name is required");
2119
+ const t = `${n.baseUrl}/api/v3.0/files`;
2120
+ s("Creating file:", t);
2121
+ const r = {
2122
+ name: e.name
2123
+ };
2124
+ e.type && (r.type = e.type), e.filename && (r.filename = e.filename), e.description && (r.description = e.description), e.tags && e.tags.length > 0 && (r.tags = e.tags), e.cameraId && (r.cameraId = e.cameraId);
2125
+ try {
2126
+ const a = await fetch(t, {
2127
+ method: "POST",
2128
+ headers: {
2129
+ Accept: "application/json",
2130
+ "Content-Type": "application/json",
2131
+ Authorization: `Bearer ${n.token}`
2132
+ },
2133
+ body: JSON.stringify(r)
2134
+ });
2135
+ if (!a.ok)
2136
+ return L(a);
2137
+ const o = await a.json();
2138
+ return s("File created:", o.id), l(o);
2139
+ } catch (a) {
2140
+ return i("NETWORK_ERROR", `Failed to create file: ${String(a)}`);
2141
+ }
2142
+ }
2143
+ async function qt(e) {
2144
+ const n = f();
2145
+ if (!n.isAuthenticated)
2146
+ return i("AUTH_REQUIRED", "Authentication required");
2147
+ if (!n.baseUrl)
2148
+ return i("AUTH_REQUIRED", "Base URL not configured");
2149
+ if (!e)
2150
+ return i("VALIDATION_ERROR", "File ID is required");
2151
+ const t = `${n.baseUrl}/api/v3.0/files/${encodeURIComponent(e)}:download`;
2152
+ s("Downloading file:", t);
2153
+ try {
2154
+ const r = await fetch(t, {
2155
+ method: "GET",
2156
+ headers: {
2157
+ Authorization: `Bearer ${n.token}`
2158
+ }
2159
+ });
2160
+ if (!r.ok)
2161
+ return L(r);
2162
+ const a = await r.blob(), o = r.headers.get("Content-Disposition");
2163
+ let c = "download";
2164
+ if (o) {
2165
+ const h = o.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
2166
+ h && h[1] && (c = h[1].replace(/['"]/g, ""));
2167
+ }
2168
+ const u = r.headers.get("Content-Type") || "application/octet-stream", R = {
2169
+ blob: a,
2170
+ filename: c,
2171
+ contentType: u,
2172
+ size: a.size
2173
+ };
2174
+ return s("File downloaded:", c, a.size, "bytes"), l(R);
2175
+ } catch (r) {
2176
+ return i("NETWORK_ERROR", `Failed to download file: ${String(r)}`);
2177
+ }
2178
+ }
2179
+ async function Ft(e) {
2180
+ const n = f();
2181
+ if (!n.isAuthenticated)
2182
+ return i("AUTH_REQUIRED", "Authentication required");
2183
+ if (!n.baseUrl)
2184
+ return i("AUTH_REQUIRED", "Base URL not configured");
2185
+ if (!e)
2186
+ return i("VALIDATION_ERROR", "File ID is required");
2187
+ const t = `${n.baseUrl}/api/v3.0/files/${encodeURIComponent(e)}`;
2188
+ s("Deleting file:", t);
2189
+ try {
2190
+ const r = await fetch(t, {
2191
+ method: "DELETE",
2192
+ headers: {
2193
+ Authorization: `Bearer ${n.token}`
2194
+ }
2195
+ });
2196
+ return r.ok ? (s("File deleted (recycled):", e), l(void 0)) : L(r);
2197
+ } catch (r) {
2198
+ return i("NETWORK_ERROR", `Failed to delete file: ${String(r)}`);
2199
+ }
2200
+ }
2201
+ async function L(e) {
2202
+ const n = e.status;
2203
+ let t;
2204
+ try {
2205
+ const r = await e.json();
2206
+ t = r.message ?? r.error ?? e.statusText;
2207
+ } catch {
2208
+ t = e.statusText || "Unknown error";
2209
+ }
2210
+ switch (n) {
2211
+ case 401:
2212
+ return i("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
2213
+ case 403:
2214
+ return i("FORBIDDEN", `Access denied: ${t}`, n);
2215
+ case 404:
2216
+ return i("NOT_FOUND", `Not found: ${t}`, n);
2217
+ case 429:
2218
+ return i("RATE_LIMITED", `Rate limited: ${t}`, n);
2219
+ default:
2220
+ return i("API_ERROR", `API error: ${t}`, n);
2221
+ }
2222
+ }
2223
+ async function mt(e) {
2224
+ const n = f();
2225
+ if (!n.isAuthenticated)
2226
+ return i("AUTH_REQUIRED", "Authentication required");
2227
+ if (!n.baseUrl)
2228
+ return i("AUTH_REQUIRED", "Base URL not configured");
2229
+ const t = new URLSearchParams();
2230
+ e?.pageSize && t.append("pageSize", String(e.pageSize)), e?.pageToken && t.append("pageToken", e.pageToken), e?.status__in && e.status__in.length > 0 && t.append("status__in", e.status__in.join(",")), e?.cameraId && t.append("cameraId", e.cameraId), e?.cameraId__in && e.cameraId__in.length > 0 && t.append("cameraId__in", e.cameraId__in.join(",")), e?.jobId && t.append("jobId", e.jobId), e?.fileId && t.append("fileId", e.fileId), e?.createTimestamp__gte && t.append("createTimestamp__gte", e.createTimestamp__gte), e?.createTimestamp__lte && t.append("createTimestamp__lte", e.createTimestamp__lte), e?.q && t.append("q", e.q), e?.sort && e.sort.length > 0 && t.append("sort", e.sort.join(","));
2231
+ const r = t.toString(), a = `${n.baseUrl}/api/v3.0/downloads${r ? `?${r}` : ""}`;
2232
+ s("Fetching downloads:", a);
2233
+ try {
2234
+ const o = await fetch(a, {
2235
+ method: "GET",
2236
+ headers: {
2237
+ Accept: "application/json",
2238
+ Authorization: `Bearer ${n.token}`
2239
+ }
2240
+ });
2241
+ if (!o.ok)
2242
+ return Y(o);
2243
+ const c = await o.json();
2244
+ return s("Downloads fetched:", c.results?.length ?? 0, "downloads"), l(c);
2245
+ } catch (o) {
2246
+ return i("NETWORK_ERROR", `Failed to fetch downloads: ${String(o)}`);
2247
+ }
2248
+ }
2249
+ async function Bt(e, n) {
2250
+ const t = f();
2251
+ if (!t.isAuthenticated)
2252
+ return i("AUTH_REQUIRED", "Authentication required");
2253
+ if (!t.baseUrl)
2254
+ return i("AUTH_REQUIRED", "Base URL not configured");
2255
+ if (!e)
2256
+ return i("VALIDATION_ERROR", "Download ID is required");
2257
+ const r = new URLSearchParams();
2258
+ n?.include && n.include.length > 0 && r.append("include", n.include.join(","));
2259
+ const a = r.toString(), o = `${t.baseUrl}/api/v3.0/downloads/${encodeURIComponent(e)}${a ? `?${a}` : ""}`;
2260
+ s("Fetching download:", o);
2261
+ try {
2262
+ const c = await fetch(o, {
2263
+ method: "GET",
2264
+ headers: {
2265
+ Accept: "application/json",
2266
+ Authorization: `Bearer ${t.token}`
2267
+ }
2268
+ });
2269
+ if (!c.ok)
2270
+ return Y(c);
2271
+ const u = await c.json();
2272
+ return s("Download fetched:", u.name, "status:", u.status), l(u);
2273
+ } catch (c) {
2274
+ return i("NETWORK_ERROR", `Failed to fetch download: ${String(c)}`);
2275
+ }
2276
+ }
2277
+ async function Pt(e) {
2278
+ const n = f();
2279
+ if (!n.isAuthenticated)
2280
+ return i("AUTH_REQUIRED", "Authentication required");
2281
+ if (!n.baseUrl)
2282
+ return i("AUTH_REQUIRED", "Base URL not configured");
2283
+ if (!e)
2284
+ return i("VALIDATION_ERROR", "Download ID is required");
2285
+ const t = `${n.baseUrl}/api/v3.0/downloads/${encodeURIComponent(e)}:download`;
2286
+ s("Downloading:", t);
2287
+ try {
2288
+ const r = await fetch(t, {
2289
+ method: "GET",
2290
+ headers: {
2291
+ Authorization: `Bearer ${n.token}`
2292
+ }
2293
+ });
2294
+ if (!r.ok)
2295
+ return Y(r);
2296
+ const a = await r.blob(), o = r.headers.get("Content-Disposition");
2297
+ let c = "download";
2298
+ if (o) {
2299
+ const h = o.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
2300
+ h && h[1] && (c = h[1].replace(/['"]/g, ""));
2301
+ }
2302
+ const u = r.headers.get("Content-Type") || "application/octet-stream", R = {
2303
+ blob: a,
2304
+ filename: c,
2305
+ contentType: u,
2306
+ size: a.size
2307
+ };
2308
+ return s("Downloaded:", c, a.size, "bytes"), l(R);
2309
+ } catch (r) {
2310
+ return i("NETWORK_ERROR", `Failed to download: ${String(r)}`);
2311
+ }
2312
+ }
2313
+ async function Y(e) {
2314
+ const n = e.status;
2315
+ let t;
2316
+ try {
2317
+ const r = await e.json();
2318
+ t = r.message ?? r.error ?? e.statusText;
2319
+ } catch {
2320
+ t = e.statusText || "Unknown error";
2321
+ }
2322
+ switch (n) {
2323
+ case 401:
2324
+ return i("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
2325
+ case 403:
2326
+ return i("FORBIDDEN", `Access denied: ${t}`, n);
2327
+ case 404:
2328
+ return i("NOT_FOUND", `Not found: ${t}`, n);
2329
+ case 429:
2330
+ return i("RATE_LIMITED", `Rate limited: ${t}`, n);
2331
+ default:
2332
+ return i("API_ERROR", `API error: ${t}`, n);
2333
+ }
2334
+ }
1884
2335
  export {
1885
- Ne as STORAGE_STRATEGY_DESCRIPTIONS,
1886
- ht as connectToEventSubscription,
1887
- ft as createEventSubscription,
1888
- We as createLayout,
1889
- _t as deleteEventSubscription,
1890
- Me as deleteLayout,
2336
+ me as STORAGE_STRATEGY_DESCRIPTIONS,
2337
+ Nt as addFile,
2338
+ Et as connectToEventSubscription,
2339
+ gt as createEventSubscription,
2340
+ Ot as createExportJob,
2341
+ Je as createLayout,
2342
+ pt as deleteEventSubscription,
2343
+ Ft as deleteFile,
2344
+ wt as deleteJob,
2345
+ Ye as deleteLayout,
2346
+ Pt as downloadDownload,
2347
+ qt as downloadFile,
1891
2348
  i as failure,
1892
2349
  I as formatTimestamp,
1893
- ee as getAccessToken,
1894
- at as getAlert,
1895
- yt as getAlertAction,
1896
- It as getAlertActionRule,
1897
- At as getAlertConditionRule,
1898
- Ie as getAuthUrl,
1899
- Ce as getBridge,
1900
- Qe as getBridges,
1901
- ze as getCamera,
1902
- He as getCameras,
1903
- Ee as getClientId,
1904
- Fe as getConfig,
1905
- me as getCurrentUser,
1906
- tt as getEvent,
1907
- pt as getEventAlertConditionRule,
1908
- Rt as getEventAlertConditionRuleFieldValues,
1909
- rt as getEventMetrics,
1910
- lt as getEventSubscription,
1911
- Ve as getLayout,
1912
- xe as getLayouts,
1913
- Je as getLiveImage,
1914
- De as getMediaSession,
1915
- ut as getNotification,
1916
- K as getProxyUrl,
1917
- Xe as getRecordedImage,
1918
- Z as getRedirectUri,
1919
- je as getStorageStrategy,
1920
- Pe as getUser,
1921
- Be as getUsers,
1922
- Se as handleAuthCallback,
1923
- qe as initEenToolkit,
1924
- Ye as initMediaSession,
1925
- Tt as listAlertActionRules,
1926
- Ut as listAlertActions,
1927
- Et as listAlertConditionRules,
1928
- ct as listAlertTypes,
1929
- ot as listAlerts,
1930
- gt as listEventAlertConditionRules,
1931
- it as listEventFieldValues,
1932
- dt as listEventSubscriptions,
1933
- nt as listEventTypes,
1934
- et as listEvents,
1935
- Ze as listFeeds,
1936
- Ge as listMedia,
1937
- st as listNotifications,
1938
- Ue as refreshToken,
1939
- ye as revokeToken,
2350
+ ie as getAccessToken,
2351
+ dt as getAlert,
2352
+ Dt as getAlertAction,
2353
+ $t as getAlertActionRule,
2354
+ yt as getAlertConditionRule,
2355
+ Se as getAuthUrl,
2356
+ Ke as getBridge,
2357
+ We as getBridges,
2358
+ Ve as getCamera,
2359
+ xe as getCameras,
2360
+ Ie as getClientId,
2361
+ He as getConfig,
2362
+ ze as getCurrentUser,
2363
+ Bt as getDownload,
2364
+ ot as getEvent,
2365
+ It as getEventAlertConditionRule,
2366
+ Tt as getEventAlertConditionRuleFieldValues,
2367
+ st as getEventMetrics,
2368
+ ht as getEventSubscription,
2369
+ Lt as getFile,
2370
+ bt as getJob,
2371
+ Ge as getLayout,
2372
+ Me as getLayouts,
2373
+ et as getLiveImage,
2374
+ we as getMediaSession,
2375
+ _t as getNotification,
2376
+ M as getProxyUrl,
2377
+ tt as getRecordedImage,
2378
+ ne as getRedirectUri,
2379
+ Be as getStorageStrategy,
2380
+ Ce as getUser,
2381
+ Qe as getUsers,
2382
+ De as handleAuthCallback,
2383
+ Pe as initEenToolkit,
2384
+ nt as initMediaSession,
2385
+ St as listAlertActionRules,
2386
+ vt as listAlertActions,
2387
+ Ut as listAlertConditionRules,
2388
+ lt as listAlertTypes,
2389
+ ut as listAlerts,
2390
+ mt as listDownloads,
2391
+ At as listEventAlertConditionRules,
2392
+ ct as listEventFieldValues,
2393
+ Rt as listEventSubscriptions,
2394
+ at as listEventTypes,
2395
+ rt as listEvents,
2396
+ it as listFeeds,
2397
+ jt as listFiles,
2398
+ kt as listJobs,
2399
+ Ze as listMedia,
2400
+ ft as listNotifications,
2401
+ $e as refreshToken,
2402
+ ve as revokeToken,
1940
2403
  l as success,
1941
- Ke as updateLayout,
2404
+ Xe as updateLayout,
1942
2405
  f as useAuthStore
1943
2406
  };
1944
2407
  //# sourceMappingURL=index.js.map