een-api-toolkit 0.0.5 → 0.0.8

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