een-api-toolkit 0.0.13 → 0.0.17

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.
package/dist/index.js CHANGED
@@ -1,296 +1,296 @@
1
1
  import { defineStore as Y } from "pinia";
2
- import { ref as c, computed as I, onMounted as L } from "vue";
3
- const T = {};
4
- let A = {};
5
- function ve(e = {}) {
6
- A = {
7
- proxyUrl: e.proxyUrl ?? T?.VITE_PROXY_URL,
8
- clientId: e.clientId ?? T?.VITE_EEN_CLIENT_ID,
9
- redirectUri: e.redirectUri ?? T?.VITE_REDIRECT_URI,
10
- debug: e.debug ?? T?.VITE_DEBUG === "true"
2
+ import { ref as u, computed as p, onMounted as x, watch as Z } from "vue";
3
+ const S = {};
4
+ let $ = {};
5
+ function Re(e = {}) {
6
+ $ = {
7
+ proxyUrl: e.proxyUrl ?? S?.VITE_PROXY_URL,
8
+ clientId: e.clientId ?? S?.VITE_EEN_CLIENT_ID,
9
+ redirectUri: e.redirectUri ?? S?.VITE_REDIRECT_URI,
10
+ debug: e.debug ?? S?.VITE_DEBUG === "true"
11
11
  };
12
12
  }
13
- function ge() {
14
- return A;
13
+ function Te() {
14
+ return $;
15
15
  }
16
- function O() {
17
- return A.proxyUrl ?? T?.VITE_PROXY_URL;
16
+ function C() {
17
+ return $.proxyUrl ?? S?.VITE_PROXY_URL;
18
18
  }
19
- function J() {
20
- return A.clientId ?? T?.VITE_EEN_CLIENT_ID;
19
+ function ee() {
20
+ return $.clientId ?? S?.VITE_EEN_CLIENT_ID;
21
21
  }
22
- function b() {
23
- return A.redirectUri ?? T?.VITE_REDIRECT_URI ?? "http://127.0.0.1:3333";
22
+ function N() {
23
+ return $.redirectUri ?? S?.VITE_REDIRECT_URI ?? "http://127.0.0.1:3333";
24
24
  }
25
- function _(e) {
25
+ function T(e) {
26
26
  return { data: e, error: null };
27
27
  }
28
- function i(e, r, t, n) {
29
- return { data: null, error: { code: e, message: r, status: t, details: n } };
28
+ function l(e, n, t, r) {
29
+ return { data: null, error: { code: e, message: n, status: t, details: r } };
30
30
  }
31
- const Z = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, ee = () => {
31
+ const te = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, ne = () => {
32
32
  try {
33
- return Z?.VITE_DEBUG === "true";
33
+ return te?.VITE_DEBUG === "true";
34
34
  } catch {
35
35
  return !1;
36
36
  }
37
37
  };
38
- function u(...e) {
39
- ee() && console.log("[een-api-toolkit]", ...e);
38
+ function c(...e) {
39
+ ne() && console.log("[een-api-toolkit]", ...e);
40
40
  }
41
- let $ = null;
42
- function te() {
43
- return $ || ($ = Promise.resolve().then(() => ue).then((e) => e.refreshToken)), $;
41
+ let O = null;
42
+ function re() {
43
+ return O || (O = Promise.resolve().then(() => ce).then((e) => e.refreshToken)), O;
44
44
  }
45
45
  const E = Y("een-auth", () => {
46
- const e = c(null), r = c(null), t = c(null), n = c(null), o = c(null), a = c(443), l = c(null), d = c(null), p = c(!1);
46
+ const e = u(null), n = u(null), t = u(null), r = u(null), o = u(null), a = u(443), i = u(null), f = u(null), I = u(!1);
47
47
  let g = null;
48
- const v = c(!1), h = c(null), x = I(() => !!e.value), y = I(() => o.value ? a.value === 443 ? `https://${o.value}` : `https://${o.value}:${a.value}` : null), R = I(() => r.value ? Date.now() >= r.value : !0), P = I(() => r.value ? Math.max(0, r.value - Date.now()) : 0);
49
- function U(s, f) {
50
- e.value = s, r.value = Date.now() + f * 1e3, S(), D(), u("Token set, expires in", f, "seconds");
48
+ const _ = u(!1), d = u(null), m = p(() => !!e.value), k = p(() => o.value ? a.value === 443 ? `https://${o.value}` : `https://${o.value}:${a.value}` : null), U = p(() => n.value ? Date.now() >= n.value : !0), A = p(() => n.value ? Math.max(0, n.value - Date.now()) : 0);
49
+ function R(s, h) {
50
+ e.value = s, n.value = Date.now() + h * 1e3, P(), w(), c("Token set, expires in", h, "seconds");
51
51
  }
52
- function w(s) {
53
- t.value = s, S();
52
+ function y(s) {
53
+ t.value = s, P();
54
54
  }
55
- function m(s) {
56
- n.value = s, S();
55
+ function v(s) {
56
+ r.value = s, P();
57
57
  }
58
- function M(s) {
58
+ function B(s) {
59
59
  if (typeof s == "string")
60
60
  try {
61
- const f = new URL(s.startsWith("http") ? s : `https://${s}`);
62
- o.value = f.hostname, a.value = f.port ? parseInt(f.port, 10) : 443;
63
- } catch (f) {
64
- u("Failed to parse URL, using as hostname:", f instanceof Error ? f.message : String(f)), o.value = s, a.value = 443;
61
+ const h = new URL(s.startsWith("http") ? s : `https://${s}`);
62
+ o.value = h.hostname, a.value = h.port ? parseInt(h.port, 10) : 443;
63
+ } catch (h) {
64
+ c("Failed to parse URL, using as hostname:", h instanceof Error ? h.message : String(h)), o.value = s, a.value = 443;
65
65
  }
66
66
  else
67
67
  o.value = s.hostname, a.value = s.port ?? 443;
68
- S(), u("Base URL set:", y.value);
68
+ P(), c("Base URL set:", k.value);
69
69
  }
70
- function j(s) {
71
- l.value = s, S();
70
+ function z(s) {
71
+ i.value = s, P();
72
72
  }
73
- function D() {
74
- if (d.value && (clearTimeout(d.value), d.value = null), !r.value || !e.value)
73
+ function w() {
74
+ if (f.value && (clearTimeout(f.value), f.value = null), !n.value || !e.value)
75
75
  return;
76
- const s = Date.now(), k = r.value - s, W = 300 * 1e3, G = k / 2, K = Math.min(W, G), X = Math.max(k - K, 60 * 1e3), C = Math.max(X, 5e3);
77
- u("Auto-refresh scheduled in", Math.round(C / 1e3), "seconds"), d.value = setTimeout(async () => {
76
+ const s = Date.now(), D = n.value - s, G = 300 * 1e3, K = D / 2, J = Math.min(G, K), X = Math.max(D - J, 60 * 1e3), j = Math.max(X, 5e3);
77
+ c("Auto-refresh scheduled in", Math.round(j / 1e3), "seconds"), f.value = setTimeout(async () => {
78
78
  await H();
79
- }, C);
79
+ }, j);
80
80
  }
81
81
  async function H() {
82
- return g ? (u("Refresh already in progress, waiting for existing refresh"), g) : (p.value = !0, u("Performing auto-refresh"), g = (async () => {
82
+ return g ? (c("Refresh already in progress, waiting for existing refresh"), g) : (I.value = !0, c("Performing auto-refresh"), g = (async () => {
83
83
  try {
84
- const f = await (await te())();
85
- f.error ? (v.value = !0, h.value = f.error.message, u("Auto-refresh failed:", f.error.message)) : (v.value = !1, h.value = null, u("Auto-refresh successful"));
84
+ const h = await (await re())();
85
+ h.error ? (_.value = !0, d.value = h.error.message, c("Auto-refresh failed:", h.error.message)) : (_.value = !1, d.value = null, c("Auto-refresh successful"));
86
86
  } catch (s) {
87
- v.value = !0, h.value = s instanceof Error ? s.message : String(s), u("Auto-refresh error:", s);
87
+ _.value = !0, d.value = s instanceof Error ? s.message : String(s), c("Auto-refresh error:", s);
88
88
  } finally {
89
- p.value = !1, g = null;
89
+ I.value = !1, g = null;
90
90
  }
91
91
  })(), g);
92
92
  }
93
- function z() {
94
- v.value = !1, h.value = null;
93
+ function M() {
94
+ _.value = !1, d.value = null;
95
95
  }
96
- function N() {
97
- d.value && (clearTimeout(d.value), d.value = null), e.value = null, r.value = null, t.value = null, n.value = null, o.value = null, a.value = 443, l.value = null, v.value = !1, h.value = null, Q(), u("Logged out");
96
+ function F() {
97
+ f.value && (clearTimeout(f.value), f.value = null), e.value = null, n.value = null, t.value = null, r.value = null, o.value = null, a.value = 443, i.value = null, _.value = !1, d.value = null, W(), c("Logged out");
98
98
  }
99
99
  function V() {
100
- q(), e.value && !R.value ? (D(), u("Initialized from storage")) : e.value && R.value && (u("Stored token expired, clearing"), N());
100
+ Q(), e.value && !U.value ? (w(), c("Initialized from storage")) : e.value && U.value && (c("Stored token expired, clearing"), F());
101
101
  }
102
- function S() {
102
+ function P() {
103
103
  try {
104
- e.value && localStorage.setItem("een_token", e.value), r.value && localStorage.setItem("een_tokenExpiration", String(r.value)), t.value && localStorage.setItem("een_refreshTokenMarker", t.value), n.value && localStorage.setItem("een_sessionId", n.value), o.value && localStorage.setItem("een_hostname", o.value), a.value !== 443 && localStorage.setItem("een_port", String(a.value)), l.value && localStorage.setItem("een_userProfile", JSON.stringify(l.value));
104
+ e.value && localStorage.setItem("een_token", e.value), n.value && localStorage.setItem("een_tokenExpiration", String(n.value)), t.value && localStorage.setItem("een_refreshTokenMarker", t.value), r.value && localStorage.setItem("een_sessionId", r.value), o.value && localStorage.setItem("een_hostname", o.value), a.value !== 443 && localStorage.setItem("een_port", String(a.value)), i.value && localStorage.setItem("een_userProfile", JSON.stringify(i.value));
105
105
  } catch (s) {
106
- u("Failed to save to localStorage:", s instanceof Error ? s.message : String(s));
106
+ c("Failed to save to localStorage:", s instanceof Error ? s.message : String(s));
107
107
  }
108
108
  }
109
- function q() {
109
+ function Q() {
110
110
  try {
111
111
  e.value = localStorage.getItem("een_token");
112
112
  const s = localStorage.getItem("een_tokenExpiration");
113
- r.value = s ? parseInt(s, 10) : null, t.value = localStorage.getItem("een_refreshTokenMarker"), n.value = localStorage.getItem("een_sessionId"), o.value = localStorage.getItem("een_hostname");
114
- const f = localStorage.getItem("een_port");
115
- a.value = f ? parseInt(f, 10) : 443;
116
- const k = localStorage.getItem("een_userProfile");
117
- l.value = k ? JSON.parse(k) : null;
113
+ n.value = s ? parseInt(s, 10) : null, t.value = localStorage.getItem("een_refreshTokenMarker"), r.value = localStorage.getItem("een_sessionId"), o.value = localStorage.getItem("een_hostname");
114
+ const h = localStorage.getItem("een_port");
115
+ a.value = h ? parseInt(h, 10) : 443;
116
+ const D = localStorage.getItem("een_userProfile");
117
+ i.value = D ? JSON.parse(D) : null;
118
118
  } catch (s) {
119
- u("Failed to load from localStorage:", s instanceof Error ? s.message : String(s));
119
+ c("Failed to load from localStorage:", s instanceof Error ? s.message : String(s));
120
120
  }
121
121
  }
122
- function Q() {
122
+ function W() {
123
123
  try {
124
124
  localStorage.removeItem("een_token"), localStorage.removeItem("een_tokenExpiration"), localStorage.removeItem("een_refreshTokenMarker"), localStorage.removeItem("een_sessionId"), localStorage.removeItem("een_hostname"), localStorage.removeItem("een_port"), localStorage.removeItem("een_userProfile");
125
125
  } catch (s) {
126
- u("Failed to clear localStorage:", s instanceof Error ? s.message : String(s));
126
+ c("Failed to clear localStorage:", s instanceof Error ? s.message : String(s));
127
127
  }
128
128
  }
129
129
  return {
130
130
  // State
131
131
  token: e,
132
- tokenExpiration: r,
132
+ tokenExpiration: n,
133
133
  refreshTokenMarker: t,
134
- sessionId: n,
134
+ sessionId: r,
135
135
  hostname: o,
136
136
  port: a,
137
- userProfile: l,
138
- isRefreshing: p,
139
- refreshFailed: v,
140
- refreshFailedMessage: h,
137
+ userProfile: i,
138
+ isRefreshing: I,
139
+ refreshFailed: _,
140
+ refreshFailedMessage: d,
141
141
  // Computed
142
- isAuthenticated: x,
143
- baseUrl: y,
144
- isTokenExpired: R,
145
- tokenExpiresIn: P,
142
+ isAuthenticated: m,
143
+ baseUrl: k,
144
+ isTokenExpired: U,
145
+ tokenExpiresIn: A,
146
146
  // Actions
147
- setToken: U,
148
- setRefreshTokenMarker: w,
149
- setSessionId: m,
150
- setBaseUrl: M,
151
- setUserProfile: j,
152
- setupAutoRefresh: D,
153
- clearRefreshFailed: z,
154
- logout: N,
147
+ setToken: R,
148
+ setRefreshTokenMarker: y,
149
+ setSessionId: v,
150
+ setBaseUrl: B,
151
+ setUserProfile: z,
152
+ setupAutoRefresh: w,
153
+ clearRefreshFailed: M,
154
+ logout: F,
155
155
  initialize: V
156
156
  };
157
- }), re = "https://auth.eagleeyenetworks.com/oauth2/authorize";
158
- function ne() {
159
- const e = J();
157
+ }), oe = "https://auth.eagleeyenetworks.com/oauth2/authorize";
158
+ function ae() {
159
+ const e = ee();
160
160
  if (!e)
161
161
  throw new Error("Client ID not configured. Call initEenToolkit() or set VITE_EEN_CLIENT_ID");
162
- const r = crypto.randomUUID();
162
+ const n = crypto.randomUUID();
163
163
  try {
164
- sessionStorage.setItem("een_oauth_state", r);
164
+ sessionStorage.setItem("een_oauth_state", n);
165
165
  } catch {
166
166
  }
167
167
  const t = new URLSearchParams({
168
168
  client_id: e,
169
169
  response_type: "code",
170
170
  scope: "vms.all",
171
- redirect_uri: b(),
172
- state: r
171
+ redirect_uri: N(),
172
+ state: n
173
173
  });
174
- return u("Generated auth URL with state:", r), `${re}?${t.toString()}`;
174
+ return c("Generated auth URL with state:", n), `${oe}?${t.toString()}`;
175
175
  }
176
- async function B(e) {
177
- const r = O();
178
- if (!r)
179
- return i("AUTH_FAILED", "Proxy URL not configured. Call initEenToolkit() or set VITE_PROXY_URL");
176
+ async function b(e) {
177
+ const n = C();
178
+ if (!n)
179
+ return l("AUTH_FAILED", "Proxy URL not configured. Call initEenToolkit() or set VITE_PROXY_URL");
180
180
  const t = new URLSearchParams({
181
181
  code: e,
182
- redirect_uri: b()
182
+ redirect_uri: N()
183
183
  });
184
184
  try {
185
- const n = await fetch(`${r}/proxy/getAccessToken?${t.toString()}`, {
185
+ const r = await fetch(`${n}/proxy/getAccessToken?${t.toString()}`, {
186
186
  method: "POST",
187
187
  credentials: "include",
188
188
  headers: {
189
189
  Accept: "application/json"
190
190
  }
191
191
  });
192
- if (!n.ok) {
193
- const a = await n.text().catch(() => "Unknown error");
194
- return i("AUTH_FAILED", `Token exchange failed: ${a}`, n.status);
192
+ if (!r.ok) {
193
+ const a = await r.text().catch(() => "Unknown error");
194
+ return l("AUTH_FAILED", `Token exchange failed: ${a}`, r.status);
195
195
  }
196
- const o = await n.json();
197
- return u("Token received, expires in:", o.expiresIn), _(o);
198
- } catch (n) {
199
- return i("NETWORK_ERROR", `Failed to exchange code: ${String(n)}`);
196
+ const o = await r.json();
197
+ return c("Token received, expires in:", o.expiresIn), T(o);
198
+ } catch (r) {
199
+ return l("NETWORK_ERROR", `Failed to exchange code: ${String(r)}`);
200
200
  }
201
201
  }
202
- async function oe() {
203
- const e = O();
202
+ async function ie() {
203
+ const e = C();
204
204
  if (!e)
205
- return i("AUTH_FAILED", "Proxy URL not configured");
206
- const r = E();
205
+ return l("AUTH_FAILED", "Proxy URL not configured");
206
+ const n = E();
207
207
  try {
208
208
  const t = {
209
209
  Accept: "application/json"
210
210
  };
211
- r.sessionId && (t.Authorization = `Bearer ${r.sessionId}`);
212
- const n = await fetch(`${e}/proxy/refreshAccessToken`, {
211
+ n.sessionId && (t.Authorization = `Bearer ${n.sessionId}`);
212
+ const r = await fetch(`${e}/proxy/refreshAccessToken`, {
213
213
  method: "POST",
214
214
  credentials: "include",
215
215
  headers: t
216
216
  });
217
- if (!n.ok) {
218
- const a = await n.text().catch(() => "Unknown error");
219
- return i("AUTH_FAILED", `Token refresh failed: ${a}`, n.status);
217
+ if (!r.ok) {
218
+ const a = await r.text().catch(() => "Unknown error");
219
+ return l("AUTH_FAILED", `Token refresh failed: ${a}`, r.status);
220
220
  }
221
- const o = await n.json();
222
- return r.setToken(o.accessToken, o.expiresIn), u("Token refreshed, expires in:", o.expiresIn), _(o);
221
+ const o = await r.json();
222
+ return n.setToken(o.accessToken, o.expiresIn), c("Token refreshed, expires in:", o.expiresIn), T(o);
223
223
  } catch (t) {
224
- return i("NETWORK_ERROR", `Failed to refresh token: ${String(t)}`);
224
+ return l("NETWORK_ERROR", `Failed to refresh token: ${String(t)}`);
225
225
  }
226
226
  }
227
- async function ae() {
228
- const e = O();
227
+ async function se() {
228
+ const e = C();
229
229
  if (!e)
230
- return i("AUTH_FAILED", "Proxy URL not configured");
231
- const r = E();
230
+ return l("AUTH_FAILED", "Proxy URL not configured");
231
+ const n = E();
232
232
  try {
233
233
  const t = {
234
234
  Accept: "application/json"
235
235
  };
236
- r.sessionId && (t.Authorization = `Bearer ${r.sessionId}`);
237
- const n = await fetch(`${e}/proxy/revoke`, {
236
+ n.sessionId && (t.Authorization = `Bearer ${n.sessionId}`);
237
+ const r = await fetch(`${e}/proxy/revoke`, {
238
238
  method: "POST",
239
239
  credentials: "include",
240
240
  headers: t
241
241
  });
242
- if (r.logout(), !n.ok) {
243
- const o = await n.text().catch(() => "Unknown error");
244
- return i("AUTH_FAILED", `Token revocation failed: ${o}`, n.status);
242
+ if (n.logout(), !r.ok) {
243
+ const o = await r.text().catch(() => "Unknown error");
244
+ return l("AUTH_FAILED", `Token revocation failed: ${o}`, r.status);
245
245
  }
246
- return u("Token revoked"), _(void 0);
246
+ return c("Token revoked"), T(void 0);
247
247
  } catch (t) {
248
- return r.logout(), i("NETWORK_ERROR", `Failed to revoke token: ${String(t)}`);
248
+ return n.logout(), l("NETWORK_ERROR", `Failed to revoke token: ${String(t)}`);
249
249
  }
250
250
  }
251
- async function se(e, r) {
251
+ async function le(e, n) {
252
252
  let t = null;
253
253
  try {
254
254
  t = sessionStorage.getItem("een_oauth_state"), sessionStorage.removeItem("een_oauth_state");
255
255
  } catch {
256
256
  }
257
257
  if (!t)
258
- return i("AUTH_FAILED", "No OAuth state found. Please restart the login process.");
259
- if (!le(r, t))
260
- return i("AUTH_FAILED", "Invalid OAuth state. Possible CSRF attack.");
261
- u("State validated, exchanging code for token");
262
- const n = await B(e);
263
- if (n.error)
264
- return n;
265
- const o = E(), a = n.data;
266
- return o.setToken(a.accessToken, a.expiresIn), o.setRefreshTokenMarker("present"), o.setSessionId(a.sessionId), o.setBaseUrl(a.httpsBaseUrl), u("Auth callback complete, user:", a.userEmail), _(a);
258
+ return l("AUTH_FAILED", "No OAuth state found. Please restart the login process.");
259
+ if (!ue(n, t))
260
+ return l("AUTH_FAILED", "Invalid OAuth state. Possible CSRF attack.");
261
+ c("State validated, exchanging code for token");
262
+ const r = await b(e);
263
+ if (r.error)
264
+ return r;
265
+ const o = E(), a = r.data;
266
+ return o.setToken(a.accessToken, a.expiresIn), o.setRefreshTokenMarker("present"), o.setSessionId(a.sessionId), o.setBaseUrl(a.httpsBaseUrl), c("Auth callback complete, user:", a.userEmail), T(a);
267
267
  }
268
- function le(e, r) {
269
- if (e.length !== r.length)
268
+ function ue(e, n) {
269
+ if (e.length !== n.length)
270
270
  return !1;
271
271
  let t = 0;
272
- for (let n = 0; n < e.length; n++)
273
- t |= e.charCodeAt(n) ^ r.charCodeAt(n);
272
+ for (let r = 0; r < e.length; r++)
273
+ t |= e.charCodeAt(r) ^ n.charCodeAt(r);
274
274
  return t === 0;
275
275
  }
276
- const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
276
+ const ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
277
277
  __proto__: null,
278
- getAccessToken: B,
279
- getAuthUrl: ne,
280
- handleAuthCallback: se,
281
- refreshToken: oe,
282
- revokeToken: ae
278
+ getAccessToken: b,
279
+ getAuthUrl: ae,
280
+ handleAuthCallback: le,
281
+ refreshToken: ie,
282
+ revokeToken: se
283
283
  }, Symbol.toStringTag, { value: "Module" }));
284
- async function ie() {
284
+ async function de() {
285
285
  const e = E();
286
286
  if (!e.isAuthenticated)
287
- return i("AUTH_REQUIRED", "Authentication required");
287
+ return l("AUTH_REQUIRED", "Authentication required");
288
288
  if (!e.baseUrl)
289
- return i("AUTH_REQUIRED", "Base URL not configured");
290
- const r = `${e.baseUrl}/api/v3.0/users/self`;
291
- u("Fetching current user:", r);
289
+ return l("AUTH_REQUIRED", "Base URL not configured");
290
+ const n = `${e.baseUrl}/api/v3.0/users/self`;
291
+ c("Fetching current user:", n);
292
292
  try {
293
- const t = await fetch(r, {
293
+ const t = await fetch(n, {
294
294
  method: "GET",
295
295
  headers: {
296
296
  Accept: "application/json",
@@ -298,173 +298,306 @@ async function ie() {
298
298
  }
299
299
  });
300
300
  if (!t.ok)
301
- return F(t);
302
- const n = await t.json();
303
- return u("Current user fetched:", n.email), e.setUserProfile(n), _(n);
301
+ return L(t);
302
+ const r = await t.json();
303
+ return c("Current user fetched:", r.email), e.setUserProfile(r), T(r);
304
304
  } catch (t) {
305
- return i("NETWORK_ERROR", `Failed to fetch current user: ${String(t)}`);
305
+ return l("NETWORK_ERROR", `Failed to fetch current user: ${String(t)}`);
306
306
  }
307
307
  }
308
- async function ce(e) {
309
- const r = E();
310
- if (!r.isAuthenticated)
311
- return i("AUTH_REQUIRED", "Authentication required");
312
- if (!r.baseUrl)
313
- return i("AUTH_REQUIRED", "Base URL not configured");
308
+ async function fe(e) {
309
+ const n = E();
310
+ if (!n.isAuthenticated)
311
+ return l("AUTH_REQUIRED", "Authentication required");
312
+ if (!n.baseUrl)
313
+ return l("AUTH_REQUIRED", "Base URL not configured");
314
314
  const t = new URLSearchParams();
315
315
  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(","));
316
- const n = t.toString(), o = `${r.baseUrl}/api/v3.0/users${n ? `?${n}` : ""}`;
317
- u("Fetching users:", o);
316
+ const r = t.toString(), o = `${n.baseUrl}/api/v3.0/users${r ? `?${r}` : ""}`;
317
+ c("Fetching users:", o);
318
318
  try {
319
319
  const a = await fetch(o, {
320
320
  method: "GET",
321
321
  headers: {
322
322
  Accept: "application/json",
323
- Authorization: `Bearer ${r.token}`
323
+ Authorization: `Bearer ${n.token}`
324
324
  }
325
325
  });
326
326
  if (!a.ok)
327
- return F(a);
328
- const l = await a.json();
329
- return u("Users fetched:", l.results?.length ?? 0, "users"), _(l);
327
+ return L(a);
328
+ const i = await a.json();
329
+ return c("Users fetched:", i.results?.length ?? 0, "users"), T(i);
330
330
  } catch (a) {
331
- return i("NETWORK_ERROR", `Failed to fetch users: ${String(a)}`);
331
+ return l("NETWORK_ERROR", `Failed to fetch users: ${String(a)}`);
332
332
  }
333
333
  }
334
- async function fe(e, r) {
334
+ async function _e(e, n) {
335
335
  const t = E();
336
336
  if (!t.isAuthenticated)
337
- return i("AUTH_REQUIRED", "Authentication required");
337
+ return l("AUTH_REQUIRED", "Authentication required");
338
338
  if (!t.baseUrl)
339
- return i("AUTH_REQUIRED", "Base URL not configured");
339
+ return l("AUTH_REQUIRED", "Base URL not configured");
340
340
  if (!e)
341
- return i("VALIDATION_ERROR", "User ID is required");
342
- const n = new URLSearchParams();
343
- r?.include && r.include.length > 0 && n.append("include", r.include.join(","));
344
- const o = n.toString(), a = `${t.baseUrl}/api/v3.0/users/${encodeURIComponent(e)}${o ? `?${o}` : ""}`;
345
- u("Fetching user:", a);
341
+ return l("VALIDATION_ERROR", "User ID is required");
342
+ const r = new URLSearchParams();
343
+ n?.include && n.include.length > 0 && r.append("include", n.include.join(","));
344
+ const o = r.toString(), a = `${t.baseUrl}/api/v3.0/users/${encodeURIComponent(e)}${o ? `?${o}` : ""}`;
345
+ c("Fetching user:", a);
346
346
  try {
347
- const l = await fetch(a, {
347
+ const i = await fetch(a, {
348
348
  method: "GET",
349
349
  headers: {
350
350
  Accept: "application/json",
351
351
  Authorization: `Bearer ${t.token}`
352
352
  }
353
353
  });
354
- if (!l.ok)
355
- return F(l);
356
- const d = await l.json();
357
- return u("User fetched:", d.email), _(d);
358
- } catch (l) {
359
- return i("NETWORK_ERROR", `Failed to fetch user: ${String(l)}`);
354
+ if (!i.ok)
355
+ return L(i);
356
+ const f = await i.json();
357
+ return c("User fetched:", f.email), T(f);
358
+ } catch (i) {
359
+ return l("NETWORK_ERROR", `Failed to fetch user: ${String(i)}`);
360
360
  }
361
361
  }
362
- async function F(e) {
363
- const r = e.status;
362
+ async function L(e) {
363
+ const n = e.status;
364
364
  let t;
365
365
  try {
366
- const n = await e.json();
367
- t = n.message ?? n.error ?? e.statusText;
366
+ const r = await e.json();
367
+ t = r.message ?? r.error ?? e.statusText;
368
368
  } catch {
369
369
  t = e.statusText || "Unknown error";
370
370
  }
371
- switch (r) {
371
+ switch (n) {
372
372
  case 401:
373
- return i("AUTH_REQUIRED", `Authentication failed: ${t}`, r);
373
+ return l("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
374
374
  case 403:
375
- return i("FORBIDDEN", `Access denied: ${t}`, r);
375
+ return l("FORBIDDEN", `Access denied: ${t}`, n);
376
376
  case 404:
377
- return i("NOT_FOUND", `Not found: ${t}`, r);
377
+ return l("NOT_FOUND", `Not found: ${t}`, n);
378
378
  case 429:
379
- return i("RATE_LIMITED", `Rate limited: ${t}`, r);
379
+ return l("RATE_LIMITED", `Rate limited: ${t}`, n);
380
380
  default:
381
- return i("API_ERROR", `API error: ${t}`, r);
381
+ return l("API_ERROR", `API error: ${t}`, n);
382
382
  }
383
383
  }
384
- function me(e) {
385
- const r = c(null), t = c(!1), n = c(null), o = async () => {
386
- t.value = !0, n.value = null;
387
- const l = await ie();
388
- return l.error ? (n.value = l.error, r.value = null) : r.value = l.data, t.value = !1, l;
384
+ function pe(e) {
385
+ const n = u(null), t = u(!1), r = u(null), o = async () => {
386
+ t.value = !0, r.value = null;
387
+ const i = await de();
388
+ return i.error ? (r.value = i.error, n.value = null) : n.value = i.data, t.value = !1, i;
389
389
  }, a = o;
390
- return e?.immediate !== !1 && L(o), {
391
- user: r,
390
+ return e?.immediate !== !1 && x(o), {
391
+ user: n,
392
392
  loading: t,
393
- error: n,
393
+ error: r,
394
394
  fetch: o,
395
395
  refresh: a
396
396
  };
397
397
  }
398
- function pe(e, r) {
399
- const t = c([]), n = c(!1), o = c(null), a = c(void 0), l = c(void 0), d = c(void 0), p = I(() => !!a.value), g = I(() => !!l.value), v = c(e ?? {}), h = async (U) => {
400
- n.value = !0, o.value = null;
401
- const w = { ...v.value, ...U }, m = await ce(w);
402
- return m.error ? (o.value = m.error, t.value = [], a.value = void 0, l.value = void 0, d.value = void 0) : (t.value = m.data.results, a.value = m.data.nextPageToken, l.value = m.data.prevPageToken, d.value = m.data.totalSize), n.value = !1, m;
403
- }, x = () => h(), y = async () => {
398
+ function Ee(e, n) {
399
+ const t = u([]), r = u(!1), o = u(null), a = u(void 0), i = u(void 0), f = u(void 0), I = p(() => !!a.value), g = p(() => !!i.value), _ = u(e ?? {}), d = async (R) => {
400
+ r.value = !0, o.value = null;
401
+ const y = { ..._.value, ...R }, v = await fe(y);
402
+ return v.error ? (o.value = v.error, t.value = [], a.value = void 0, i.value = void 0, f.value = void 0) : (t.value = v.data.results, a.value = v.data.nextPageToken, i.value = v.data.prevPageToken, f.value = v.data.totalSize), r.value = !1, v;
403
+ }, m = () => d(), k = async () => {
404
404
  if (a.value)
405
- return h({ ...v.value, pageToken: a.value });
406
- }, R = async () => {
407
- if (l.value)
408
- return h({ ...v.value, pageToken: l.value });
409
- }, P = (U) => {
410
- v.value = U;
405
+ return d({ ..._.value, pageToken: a.value });
406
+ }, U = async () => {
407
+ if (i.value)
408
+ return d({ ..._.value, pageToken: i.value });
409
+ }, A = (R) => {
410
+ _.value = R;
411
411
  };
412
- return r?.immediate !== !1 && L(h), {
412
+ return n?.immediate !== !1 && x(d), {
413
413
  users: t,
414
- loading: n,
414
+ loading: r,
415
415
  error: o,
416
416
  nextPageToken: a,
417
- prevPageToken: l,
418
- totalSize: d,
419
- hasNextPage: p,
417
+ prevPageToken: i,
418
+ totalSize: f,
419
+ hasNextPage: I,
420
420
  hasPrevPage: g,
421
- params: v,
422
- fetch: h,
423
- refresh: x,
424
- fetchNextPage: y,
425
- fetchPrevPage: R,
426
- setParams: P
421
+ params: _,
422
+ fetch: d,
423
+ refresh: m,
424
+ fetchNextPage: k,
425
+ fetchPrevPage: U,
426
+ setParams: A
427
427
  };
428
428
  }
429
- function Te(e, r) {
430
- const t = c(null), n = c(!1), o = c(null), a = () => typeof e == "function" ? e() : e, l = async (p) => {
429
+ function Ue(e, n) {
430
+ const t = u(null), r = u(!1), o = u(null), a = () => typeof e == "function" ? e() : e, i = async (I) => {
431
431
  const g = a();
432
432
  if (!g)
433
433
  return o.value = { code: "VALIDATION_ERROR", message: "User ID is required" }, { data: null, error: o.value };
434
- n.value = !0, o.value = null;
435
- const v = {
436
- include: r?.include,
437
- ...p
438
- }, h = await fe(g, v);
439
- return h.error ? (o.value = h.error, t.value = null) : t.value = h.data, n.value = !1, h;
440
- }, d = () => l();
441
- return r?.immediate !== !1 && a() && L(l), {
434
+ r.value = !0, o.value = null;
435
+ const _ = {
436
+ include: n?.include,
437
+ ...I
438
+ }, d = await _e(g, _);
439
+ return d.error ? (o.value = d.error, t.value = null) : t.value = d.data, r.value = !1, d;
440
+ }, f = () => i();
441
+ return n?.immediate !== !1 && a() && x(i), {
442
442
  user: t,
443
- loading: n,
443
+ loading: r,
444
+ error: o,
445
+ fetch: i,
446
+ refresh: f
447
+ };
448
+ }
449
+ async function he(e) {
450
+ const n = E();
451
+ if (!n.isAuthenticated)
452
+ return l("AUTH_REQUIRED", "Authentication required");
453
+ if (!n.baseUrl)
454
+ return l("AUTH_REQUIRED", "Base URL not configured");
455
+ const t = new URLSearchParams();
456
+ 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?.sort && e.sort.length > 0 && t.append("sort", e.sort.join(",")), e?.locationId__in && e.locationId__in.length > 0 && t.append("locationId__in", e.locationId__in.join(",")), e?.bridgeId__in && e.bridgeId__in.length > 0 && t.append("bridgeId__in", e.bridgeId__in.join(",")), e?.multiCameraId && t.append("multiCameraId", e.multiCameraId), e?.multiCameraId__ne && t.append("multiCameraId__ne", e.multiCameraId__ne), e?.multiCameraId__in && e.multiCameraId__in.length > 0 && t.append("multiCameraId__in", e.multiCameraId__in.join(",")), e?.tags__contains && e.tags__contains.length > 0 && t.append("tags__contains", e.tags__contains.join(",")), e?.tags__any && e.tags__any.length > 0 && t.append("tags__any", e.tags__any.join(",")), e?.packages__contains && e.packages__contains.length > 0 && t.append("packages__contains", e.packages__contains.join(",")), e?.name && t.append("name", e.name), e?.name__contains && t.append("name__contains", e.name__contains), e?.name__in && e.name__in.length > 0 && t.append("name__in", e.name__in.join(",")), e?.id__in && e.id__in.length > 0 && t.append("id__in", e.id__in.join(",")), e?.id__notIn && e.id__notIn.length > 0 && t.append("id__notIn", e.id__notIn.join(",")), e?.id__contains && t.append("id__contains", e.id__contains), e?.layoutId && t.append("layoutId", e.layoutId), typeof e?.shared == "boolean" && t.append("shareDetails.shared", String(e.shared)), e?.sharedCameraAccount && t.append("shareDetails.accountId", e.sharedCameraAccount), typeof e?.firstResponder == "boolean" && t.append("shareDetails.firstResponder", String(e.firstResponder)), typeof e?.directToCloud == "boolean" && t.append("deviceInfo.directToCloud", String(e.directToCloud)), e?.speakerId__in && e.speakerId__in.length > 0 && t.append("speakerId__in", e.speakerId__in.join(",")), e?.q && t.append("q", e.q), typeof e?.qRelevance__gte == "number" && t.append("qRelevance__gte", String(e.qRelevance__gte)), e?.enabledAnalytics__contains && e.enabledAnalytics__contains.length > 0 && t.append("enabledAnalytics__contains", e.enabledAnalytics__contains.join(",")), e?.status__in && e.status__in.length > 0 && t.append("status__in", e.status__in.join(",")), e?.status__ne && t.append("status__ne", e.status__ne);
457
+ const r = t.toString(), o = `${n.baseUrl}/api/v3.0/cameras${r ? `?${r}` : ""}`;
458
+ c("Fetching cameras:", o);
459
+ try {
460
+ const a = await fetch(o, {
461
+ method: "GET",
462
+ headers: {
463
+ Accept: "application/json",
464
+ Authorization: `Bearer ${n.token}`
465
+ }
466
+ });
467
+ if (!a.ok)
468
+ return q(a);
469
+ const i = await a.json();
470
+ return c("Cameras fetched:", i.results?.length ?? 0, "cameras"), T(i);
471
+ } catch (a) {
472
+ return l("NETWORK_ERROR", `Failed to fetch cameras: ${String(a)}`);
473
+ }
474
+ }
475
+ async function ge(e, n) {
476
+ const t = E();
477
+ if (!t.isAuthenticated)
478
+ return l("AUTH_REQUIRED", "Authentication required");
479
+ if (!t.baseUrl)
480
+ return l("AUTH_REQUIRED", "Base URL not configured");
481
+ if (!e)
482
+ return l("VALIDATION_ERROR", "Camera ID is required");
483
+ const r = new URLSearchParams();
484
+ n?.include && n.include.length > 0 && r.append("include", n.include.join(","));
485
+ const o = r.toString(), a = `${t.baseUrl}/api/v3.0/cameras/${encodeURIComponent(e)}${o ? `?${o}` : ""}`;
486
+ c("Fetching camera:", a);
487
+ try {
488
+ const i = await fetch(a, {
489
+ method: "GET",
490
+ headers: {
491
+ Accept: "application/json",
492
+ Authorization: `Bearer ${t.token}`
493
+ }
494
+ });
495
+ if (!i.ok)
496
+ return q(i);
497
+ const f = await i.json();
498
+ return c("Camera fetched:", f.name), T(f);
499
+ } catch (i) {
500
+ return l("NETWORK_ERROR", `Failed to fetch camera: ${String(i)}`);
501
+ }
502
+ }
503
+ async function q(e) {
504
+ const n = e.status;
505
+ let t;
506
+ try {
507
+ const r = await e.json();
508
+ t = r.message ?? r.error ?? e.statusText;
509
+ } catch (r) {
510
+ c("Failed to parse error response JSON:", r), t = e.statusText || "Unknown error";
511
+ }
512
+ switch (n) {
513
+ case 401:
514
+ return l("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
515
+ case 403:
516
+ return l("FORBIDDEN", `Access denied: ${t}`, n);
517
+ case 404:
518
+ return l("NOT_FOUND", `Not found: ${t}`, n);
519
+ case 429:
520
+ return l("RATE_LIMITED", `Rate limited: ${t}`, n);
521
+ default:
522
+ return l("API_ERROR", `API error: ${t}`, n);
523
+ }
524
+ }
525
+ function Se(e, n) {
526
+ const t = u([]), r = u(!1), o = u(null), a = u(void 0), i = u(void 0), f = u(void 0), I = p(() => !!a.value), g = p(() => !!i.value), _ = u(e ?? {}), d = async (R) => {
527
+ r.value = !0, o.value = null;
528
+ const y = { ..._.value, ...R }, v = await he(y);
529
+ return v.error ? (o.value = v.error, t.value = [], a.value = void 0, i.value = void 0, f.value = void 0) : (t.value = v.data.results, a.value = v.data.nextPageToken, i.value = v.data.prevPageToken, f.value = v.data.totalSize), r.value = !1, v;
530
+ }, m = () => d(), k = async () => {
531
+ if (a.value)
532
+ return d({ ..._.value, pageToken: a.value });
533
+ }, U = async () => {
534
+ if (i.value)
535
+ return d({ ..._.value, pageToken: i.value });
536
+ }, A = (R) => {
537
+ _.value = R;
538
+ };
539
+ return n?.immediate !== !1 && x(d), {
540
+ cameras: t,
541
+ loading: r,
542
+ error: o,
543
+ nextPageToken: a,
544
+ prevPageToken: i,
545
+ totalSize: f,
546
+ hasNextPage: I,
547
+ hasPrevPage: g,
548
+ params: _,
549
+ fetch: d,
550
+ refresh: m,
551
+ fetchNextPage: k,
552
+ fetchPrevPage: U,
553
+ setParams: A
554
+ };
555
+ }
556
+ function ke(e, n) {
557
+ const t = u(null), r = u(!1), o = u(null), a = () => typeof e == "function" ? e() : e, i = async (I) => {
558
+ const g = a();
559
+ if (!g)
560
+ return o.value = { code: "VALIDATION_ERROR", message: "Camera ID is required" }, { data: null, error: o.value };
561
+ r.value = !0, o.value = null;
562
+ const _ = {
563
+ include: n?.include,
564
+ ...I
565
+ }, d = await ge(g, _);
566
+ return d.error ? (o.value = d.error, t.value = null) : t.value = d.data, r.value = !1, d;
567
+ }, f = () => i();
568
+ return n?.immediate !== !1 && a() && x(i), typeof e == "function" && Z(e, (I, g) => {
569
+ I && I !== g && i();
570
+ }), {
571
+ camera: t,
572
+ loading: r,
444
573
  error: o,
445
- fetch: l,
446
- refresh: d
574
+ fetch: i,
575
+ refresh: f
447
576
  };
448
577
  }
449
578
  export {
450
- i as failure,
451
- B as getAccessToken,
452
- ne as getAuthUrl,
453
- J as getClientId,
454
- ge as getConfig,
455
- ie as getCurrentUser,
456
- O as getProxyUrl,
457
- b as getRedirectUri,
458
- fe as getUser,
459
- ce as getUsers,
460
- se as handleAuthCallback,
461
- ve as initEenToolkit,
462
- oe as refreshToken,
463
- ae as revokeToken,
464
- _ as success,
579
+ l as failure,
580
+ b as getAccessToken,
581
+ ae as getAuthUrl,
582
+ ge as getCamera,
583
+ he as getCameras,
584
+ ee as getClientId,
585
+ Te as getConfig,
586
+ de as getCurrentUser,
587
+ C as getProxyUrl,
588
+ N as getRedirectUri,
589
+ _e as getUser,
590
+ fe as getUsers,
591
+ le as handleAuthCallback,
592
+ Re as initEenToolkit,
593
+ ie as refreshToken,
594
+ se as revokeToken,
595
+ T as success,
465
596
  E as useAuthStore,
466
- me as useCurrentUser,
467
- Te as useUser,
468
- pe as useUsers
597
+ ke as useCamera,
598
+ Se as useCameras,
599
+ pe as useCurrentUser,
600
+ Ue as useUser,
601
+ Ee as useUsers
469
602
  };
470
603
  //# sourceMappingURL=index.js.map