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/CHANGELOG.md +223 -0
- package/README.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +263 -260
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/dist/index.js
CHANGED
|
@@ -1,121 +1,125 @@
|
|
|
1
|
-
import { defineStore as
|
|
2
|
-
import { ref as
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
proxyUrl: e.proxyUrl ??
|
|
8
|
-
clientId: e.clientId ??
|
|
9
|
-
redirectUri: e.redirectUri ??
|
|
10
|
-
debug: e.debug ??
|
|
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
|
|
14
|
-
return
|
|
13
|
+
function ge() {
|
|
14
|
+
return A;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
16
|
+
function O() {
|
|
17
|
+
return A.proxyUrl ?? T?.VITE_PROXY_URL;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
19
|
+
function J() {
|
|
20
|
+
return A.clientId ?? T?.VITE_EEN_CLIENT_ID;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
22
|
+
function b() {
|
|
23
|
+
return A.redirectUri ?? T?.VITE_REDIRECT_URI ?? "http://127.0.0.1:3333";
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function _(e) {
|
|
26
26
|
return { data: e, error: null };
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return { data: null, error: { code: e, message:
|
|
28
|
+
function i(e, r, t, n) {
|
|
29
|
+
return { data: null, error: { code: e, message: r, status: t, details: n } };
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const Z = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, ee = () => {
|
|
32
32
|
try {
|
|
33
|
-
return
|
|
33
|
+
return Z?.VITE_DEBUG === "true";
|
|
34
34
|
} catch {
|
|
35
35
|
return !1;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
function u(...e) {
|
|
39
|
-
|
|
39
|
+
ee() && console.log("[een-api-toolkit]", ...e);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
49
|
-
|
|
52
|
+
function w(s) {
|
|
53
|
+
t.value = s, S();
|
|
50
54
|
}
|
|
51
|
-
function
|
|
52
|
-
n.value = s,
|
|
55
|
+
function m(s) {
|
|
56
|
+
n.value = s, S();
|
|
53
57
|
}
|
|
54
|
-
function
|
|
58
|
+
function M(s) {
|
|
55
59
|
if (typeof s == "string")
|
|
56
60
|
try {
|
|
57
|
-
const
|
|
58
|
-
o.value =
|
|
59
|
-
} catch (
|
|
60
|
-
u("Failed to parse URL, using as hostname:",
|
|
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
|
-
|
|
68
|
+
S(), u("Base URL set:", y.value);
|
|
65
69
|
}
|
|
66
|
-
function
|
|
67
|
-
l.value = s,
|
|
70
|
+
function j(s) {
|
|
71
|
+
l.value = s, S();
|
|
68
72
|
}
|
|
69
|
-
function
|
|
70
|
-
if (d.value && (clearTimeout(d.value), d.value = null), !
|
|
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(),
|
|
73
|
-
u("Auto-refresh scheduled in", Math.round(
|
|
74
|
-
await
|
|
75
|
-
},
|
|
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
|
|
78
|
-
return
|
|
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
|
|
81
|
-
|
|
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,
|
|
87
|
+
v.value = !0, h.value = s instanceof Error ? s.message : String(s), u("Auto-refresh error:", s);
|
|
84
88
|
} finally {
|
|
85
|
-
|
|
89
|
+
p.value = !1, g = null;
|
|
86
90
|
}
|
|
87
|
-
})(),
|
|
91
|
+
})(), g);
|
|
88
92
|
}
|
|
89
|
-
function
|
|
90
|
-
v.value = !1,
|
|
93
|
+
function z() {
|
|
94
|
+
v.value = !1, h.value = null;
|
|
91
95
|
}
|
|
92
|
-
function
|
|
93
|
-
d.value && (clearTimeout(d.value), d.value = null), e.value = null,
|
|
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
|
|
96
|
-
|
|
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
|
|
102
|
+
function S() {
|
|
99
103
|
try {
|
|
100
|
-
e.value && localStorage.setItem("een_token", e.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
|
|
109
|
+
function q() {
|
|
106
110
|
try {
|
|
107
111
|
e.value = localStorage.getItem("een_token");
|
|
108
112
|
const s = localStorage.getItem("een_tokenExpiration");
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
a.value =
|
|
112
|
-
const
|
|
113
|
-
l.value =
|
|
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
|
|
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:
|
|
129
|
-
refreshTokenMarker:
|
|
132
|
+
tokenExpiration: r,
|
|
133
|
+
refreshTokenMarker: t,
|
|
130
134
|
sessionId: n,
|
|
131
135
|
hostname: o,
|
|
132
136
|
port: a,
|
|
133
137
|
userProfile: l,
|
|
134
|
-
isRefreshing:
|
|
138
|
+
isRefreshing: p,
|
|
135
139
|
refreshFailed: v,
|
|
136
|
-
refreshFailedMessage:
|
|
140
|
+
refreshFailedMessage: h,
|
|
137
141
|
// Computed
|
|
138
|
-
isAuthenticated:
|
|
139
|
-
baseUrl:
|
|
140
|
-
isTokenExpired:
|
|
141
|
-
tokenExpiresIn:
|
|
142
|
+
isAuthenticated: x,
|
|
143
|
+
baseUrl: y,
|
|
144
|
+
isTokenExpired: R,
|
|
145
|
+
tokenExpiresIn: P,
|
|
142
146
|
// Actions
|
|
143
|
-
setToken:
|
|
144
|
-
setRefreshTokenMarker:
|
|
145
|
-
setSessionId:
|
|
146
|
-
setBaseUrl:
|
|
147
|
-
setUserProfile:
|
|
148
|
-
setupAutoRefresh:
|
|
149
|
-
clearRefreshFailed:
|
|
150
|
-
logout:
|
|
151
|
-
initialize:
|
|
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
|
-
}),
|
|
154
|
-
function
|
|
155
|
-
const e =
|
|
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
|
|
162
|
+
const r = crypto.randomUUID();
|
|
159
163
|
try {
|
|
160
|
-
sessionStorage.setItem("een_oauth_state",
|
|
164
|
+
sessionStorage.setItem("een_oauth_state", r);
|
|
161
165
|
} catch {
|
|
162
166
|
}
|
|
163
|
-
const
|
|
167
|
+
const t = new URLSearchParams({
|
|
164
168
|
client_id: e,
|
|
165
169
|
response_type: "code",
|
|
166
170
|
scope: "vms.all",
|
|
167
|
-
redirect_uri:
|
|
168
|
-
state:
|
|
171
|
+
redirect_uri: b(),
|
|
172
|
+
state: r
|
|
169
173
|
});
|
|
170
|
-
return u("Generated auth URL with state:",
|
|
174
|
+
return u("Generated auth URL with state:", r), `${re}?${t.toString()}`;
|
|
171
175
|
}
|
|
172
|
-
async function
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
175
|
-
return
|
|
176
|
-
const
|
|
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:
|
|
182
|
+
redirect_uri: b()
|
|
179
183
|
});
|
|
180
184
|
try {
|
|
181
|
-
const n = await fetch(`${
|
|
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
|
|
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),
|
|
197
|
+
return u("Token received, expires in:", o.expiresIn), _(o);
|
|
194
198
|
} catch (n) {
|
|
195
|
-
return
|
|
199
|
+
return i("NETWORK_ERROR", `Failed to exchange code: ${String(n)}`);
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
|
-
async function
|
|
199
|
-
const e =
|
|
202
|
+
async function oe() {
|
|
203
|
+
const e = O();
|
|
200
204
|
if (!e)
|
|
201
|
-
return
|
|
202
|
-
const
|
|
205
|
+
return i("AUTH_FAILED", "Proxy URL not configured");
|
|
206
|
+
const r = E();
|
|
203
207
|
try {
|
|
204
|
-
const
|
|
208
|
+
const t = {
|
|
205
209
|
Accept: "application/json"
|
|
206
210
|
};
|
|
207
|
-
|
|
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:
|
|
215
|
+
headers: t
|
|
212
216
|
});
|
|
213
217
|
if (!n.ok) {
|
|
214
218
|
const a = await n.text().catch(() => "Unknown error");
|
|
215
|
-
return
|
|
219
|
+
return i("AUTH_FAILED", `Token refresh failed: ${a}`, n.status);
|
|
216
220
|
}
|
|
217
221
|
const o = await n.json();
|
|
218
|
-
return
|
|
219
|
-
} catch (
|
|
220
|
-
return
|
|
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
|
|
224
|
-
const e =
|
|
227
|
+
async function ae() {
|
|
228
|
+
const e = O();
|
|
225
229
|
if (!e)
|
|
226
|
-
return
|
|
227
|
-
const
|
|
230
|
+
return i("AUTH_FAILED", "Proxy URL not configured");
|
|
231
|
+
const r = E();
|
|
228
232
|
try {
|
|
229
|
-
const
|
|
233
|
+
const t = {
|
|
230
234
|
Accept: "application/json"
|
|
231
235
|
};
|
|
232
|
-
|
|
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:
|
|
240
|
+
headers: t
|
|
237
241
|
});
|
|
238
|
-
if (
|
|
242
|
+
if (r.logout(), !n.ok) {
|
|
239
243
|
const o = await n.text().catch(() => "Unknown error");
|
|
240
|
-
return
|
|
244
|
+
return i("AUTH_FAILED", `Token revocation failed: ${o}`, n.status);
|
|
241
245
|
}
|
|
242
|
-
return u("Token revoked"),
|
|
243
|
-
} catch (
|
|
244
|
-
return
|
|
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
|
|
248
|
-
let
|
|
251
|
+
async function se(e, r) {
|
|
252
|
+
let t = null;
|
|
249
253
|
try {
|
|
250
|
-
|
|
254
|
+
t = sessionStorage.getItem("een_oauth_state"), sessionStorage.removeItem("een_oauth_state");
|
|
251
255
|
} catch {
|
|
252
256
|
}
|
|
253
|
-
if (!
|
|
254
|
-
return
|
|
255
|
-
if (!
|
|
256
|
-
return
|
|
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
|
|
262
|
+
const n = await B(e);
|
|
259
263
|
if (n.error)
|
|
260
264
|
return n;
|
|
261
|
-
const o =
|
|
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),
|
|
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
|
|
265
|
-
if (e.length !==
|
|
268
|
+
function le(e, r) {
|
|
269
|
+
if (e.length !== r.length)
|
|
266
270
|
return !1;
|
|
267
|
-
let
|
|
271
|
+
let t = 0;
|
|
268
272
|
for (let n = 0; n < e.length; n++)
|
|
269
|
-
|
|
270
|
-
return
|
|
273
|
+
t |= e.charCodeAt(n) ^ r.charCodeAt(n);
|
|
274
|
+
return t === 0;
|
|
271
275
|
}
|
|
272
|
-
const
|
|
276
|
+
const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
273
277
|
__proto__: null,
|
|
274
|
-
getAccessToken:
|
|
275
|
-
getAuthUrl:
|
|
276
|
-
handleAuthCallback:
|
|
277
|
-
refreshToken:
|
|
278
|
-
revokeToken:
|
|
278
|
+
getAccessToken: B,
|
|
279
|
+
getAuthUrl: ne,
|
|
280
|
+
handleAuthCallback: se,
|
|
281
|
+
refreshToken: oe,
|
|
282
|
+
revokeToken: ae
|
|
279
283
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
280
|
-
async function
|
|
281
|
-
const e =
|
|
284
|
+
async function ie() {
|
|
285
|
+
const e = E();
|
|
282
286
|
if (!e.isAuthenticated)
|
|
283
|
-
return
|
|
287
|
+
return i("AUTH_REQUIRED", "Authentication required");
|
|
284
288
|
if (!e.baseUrl)
|
|
285
|
-
return
|
|
286
|
-
const
|
|
287
|
-
u("Fetching current user:",
|
|
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
|
|
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 (!
|
|
297
|
-
return
|
|
298
|
-
const n = await
|
|
299
|
-
return u("Current user fetched:", n.email), e.setUserProfile(n),
|
|
300
|
-
} catch (
|
|
301
|
-
return
|
|
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
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
|
319
|
+
const a = await fetch(o, {
|
|
317
320
|
method: "GET",
|
|
318
321
|
headers: {
|
|
319
322
|
Accept: "application/json",
|
|
320
|
-
Authorization: `Bearer ${
|
|
323
|
+
Authorization: `Bearer ${r.token}`
|
|
321
324
|
}
|
|
322
325
|
});
|
|
323
|
-
if (!
|
|
324
|
-
return
|
|
325
|
-
const
|
|
326
|
-
return u("Users fetched:",
|
|
327
|
-
} catch (
|
|
328
|
-
return
|
|
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
|
|
332
|
-
const
|
|
333
|
-
if (!
|
|
334
|
-
return
|
|
335
|
-
if (!
|
|
336
|
-
return
|
|
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
|
|
341
|
+
return i("VALIDATION_ERROR", "User ID is required");
|
|
339
342
|
const n = new URLSearchParams();
|
|
340
|
-
|
|
341
|
-
const o = n.toString(), a = `${
|
|
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 ${
|
|
351
|
+
Authorization: `Bearer ${t.token}`
|
|
349
352
|
}
|
|
350
353
|
});
|
|
351
354
|
if (!l.ok)
|
|
352
|
-
return
|
|
355
|
+
return F(l);
|
|
353
356
|
const d = await l.json();
|
|
354
|
-
return u("User fetched:", d.email),
|
|
357
|
+
return u("User fetched:", d.email), _(d);
|
|
355
358
|
} catch (l) {
|
|
356
|
-
return
|
|
359
|
+
return i("NETWORK_ERROR", `Failed to fetch user: ${String(l)}`);
|
|
357
360
|
}
|
|
358
361
|
}
|
|
359
|
-
async function
|
|
360
|
-
const
|
|
361
|
-
let
|
|
362
|
+
async function F(e) {
|
|
363
|
+
const r = e.status;
|
|
364
|
+
let t;
|
|
362
365
|
try {
|
|
363
366
|
const n = await e.json();
|
|
364
|
-
|
|
367
|
+
t = n.message ?? n.error ?? e.statusText;
|
|
365
368
|
} catch {
|
|
366
|
-
|
|
369
|
+
t = e.statusText || "Unknown error";
|
|
367
370
|
}
|
|
368
|
-
switch (
|
|
371
|
+
switch (r) {
|
|
369
372
|
case 401:
|
|
370
|
-
return
|
|
373
|
+
return i("AUTH_REQUIRED", `Authentication failed: ${t}`, r);
|
|
371
374
|
case 403:
|
|
372
|
-
return
|
|
375
|
+
return i("FORBIDDEN", `Access denied: ${t}`, r);
|
|
373
376
|
case 404:
|
|
374
|
-
return
|
|
377
|
+
return i("NOT_FOUND", `Not found: ${t}`, r);
|
|
375
378
|
case 429:
|
|
376
|
-
return
|
|
379
|
+
return i("RATE_LIMITED", `Rate limited: ${t}`, r);
|
|
377
380
|
default:
|
|
378
|
-
return
|
|
381
|
+
return i("API_ERROR", `API error: ${t}`, r);
|
|
379
382
|
}
|
|
380
383
|
}
|
|
381
|
-
function
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
const l = await
|
|
385
|
-
return l.error ? (n.value = l.error,
|
|
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
|
|
388
|
-
user:
|
|
389
|
-
loading:
|
|
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
|
|
396
|
-
const
|
|
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
|
|
399
|
-
return
|
|
400
|
-
},
|
|
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
|
|
403
|
-
},
|
|
405
|
+
return h({ ...v.value, pageToken: a.value });
|
|
406
|
+
}, R = async () => {
|
|
404
407
|
if (l.value)
|
|
405
|
-
return
|
|
406
|
-
},
|
|
407
|
-
v.value =
|
|
408
|
+
return h({ ...v.value, pageToken: l.value });
|
|
409
|
+
}, P = (U) => {
|
|
410
|
+
v.value = U;
|
|
408
411
|
};
|
|
409
|
-
return
|
|
410
|
-
users:
|
|
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:
|
|
417
|
-
hasPrevPage:
|
|
419
|
+
hasNextPage: p,
|
|
420
|
+
hasPrevPage: g,
|
|
418
421
|
params: v,
|
|
419
|
-
fetch:
|
|
420
|
-
refresh:
|
|
421
|
-
fetchNextPage:
|
|
422
|
-
fetchPrevPage:
|
|
423
|
-
setParams:
|
|
422
|
+
fetch: h,
|
|
423
|
+
refresh: x,
|
|
424
|
+
fetchNextPage: y,
|
|
425
|
+
fetchPrevPage: R,
|
|
426
|
+
setParams: P
|
|
424
427
|
};
|
|
425
428
|
}
|
|
426
|
-
function Te(e,
|
|
427
|
-
const
|
|
428
|
-
const
|
|
429
|
-
if (!
|
|
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:
|
|
434
|
-
...
|
|
435
|
-
},
|
|
436
|
-
return
|
|
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
|
|
439
|
-
user:
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
468
|
+
pe as useUsers
|
|
466
469
|
};
|
|
467
470
|
//# sourceMappingURL=index.js.map
|