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/CHANGELOG.md +72 -273
- package/README.md +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +897 -0
- package/dist/index.js +395 -262
- package/dist/index.js.map +1 -1
- package/docs/AI-CONTEXT.md +233 -3
- package/examples/vue-cameras/.env.example +13 -0
- package/examples/vue-cameras/e2e/app.spec.ts +73 -0
- package/examples/vue-cameras/index.html +13 -0
- package/examples/vue-cameras/package-lock.json +1583 -0
- package/examples/vue-cameras/package.json +28 -0
- package/examples/vue-cameras/playwright.config.ts +46 -0
- package/examples/vue-cameras/src/App.vue +108 -0
- package/examples/vue-cameras/src/main.ts +23 -0
- package/examples/vue-cameras/src/router/index.ts +68 -0
- package/examples/vue-cameras/src/views/Callback.vue +76 -0
- package/examples/vue-cameras/src/views/CameraDetail.vue +315 -0
- package/examples/vue-cameras/src/views/Cameras.vue +249 -0
- package/examples/vue-cameras/src/views/Home.vue +125 -0
- package/examples/vue-cameras/src/views/Login.vue +33 -0
- package/examples/vue-cameras/src/views/Logout.vue +66 -0
- package/examples/vue-cameras/src/vite-env.d.ts +12 -0
- package/examples/vue-cameras/tsconfig.json +21 -0
- package/examples/vue-cameras/tsconfig.node.json +10 -0
- package/examples/vue-cameras/vite.config.ts +12 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,296 +1,296 @@
|
|
|
1
1
|
import { defineStore as Y } from "pinia";
|
|
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 ??
|
|
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
|
|
14
|
-
return
|
|
13
|
+
function Te() {
|
|
14
|
+
return $;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
16
|
+
function C() {
|
|
17
|
+
return $.proxyUrl ?? S?.VITE_PROXY_URL;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
19
|
+
function ee() {
|
|
20
|
+
return $.clientId ?? S?.VITE_EEN_CLIENT_ID;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return
|
|
22
|
+
function N() {
|
|
23
|
+
return $.redirectUri ?? S?.VITE_REDIRECT_URI ?? "http://127.0.0.1:3333";
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function T(e) {
|
|
26
26
|
return { data: e, error: null };
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return { data: null, error: { code: e, message:
|
|
28
|
+
function l(e, n, t, r) {
|
|
29
|
+
return { data: null, error: { code: e, message: n, status: t, details: r } };
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const te = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, ne = () => {
|
|
32
32
|
try {
|
|
33
|
-
return
|
|
33
|
+
return te?.VITE_DEBUG === "true";
|
|
34
34
|
} catch {
|
|
35
35
|
return !1;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
function
|
|
39
|
-
|
|
38
|
+
function c(...e) {
|
|
39
|
+
ne() && console.log("[een-api-toolkit]", ...e);
|
|
40
40
|
}
|
|
41
|
-
let
|
|
42
|
-
function
|
|
43
|
-
return
|
|
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 =
|
|
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
|
|
49
|
-
function
|
|
50
|
-
e.value = s,
|
|
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
|
|
53
|
-
t.value = s,
|
|
52
|
+
function y(s) {
|
|
53
|
+
t.value = s, P();
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
55
|
+
function v(s) {
|
|
56
|
+
r.value = s, P();
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function B(s) {
|
|
59
59
|
if (typeof s == "string")
|
|
60
60
|
try {
|
|
61
|
-
const
|
|
62
|
-
o.value =
|
|
63
|
-
} catch (
|
|
64
|
-
|
|
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
|
-
|
|
68
|
+
P(), c("Base URL set:", k.value);
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
70
|
+
function z(s) {
|
|
71
|
+
i.value = s, P();
|
|
72
72
|
}
|
|
73
|
-
function
|
|
74
|
-
if (
|
|
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(),
|
|
77
|
-
|
|
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
|
-
},
|
|
79
|
+
}, j);
|
|
80
80
|
}
|
|
81
81
|
async function H() {
|
|
82
|
-
return g ? (
|
|
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
|
|
85
|
-
|
|
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
|
-
|
|
87
|
+
_.value = !0, d.value = s instanceof Error ? s.message : String(s), c("Auto-refresh error:", s);
|
|
88
88
|
} finally {
|
|
89
|
-
|
|
89
|
+
I.value = !1, g = null;
|
|
90
90
|
}
|
|
91
91
|
})(), g);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
93
|
+
function M() {
|
|
94
|
+
_.value = !1, d.value = null;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
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
|
-
|
|
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
|
|
102
|
+
function P() {
|
|
103
103
|
try {
|
|
104
|
-
e.value && localStorage.setItem("een_token", e.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
|
-
|
|
106
|
+
c("Failed to save to localStorage:", s instanceof Error ? s.message : String(s));
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function Q() {
|
|
110
110
|
try {
|
|
111
111
|
e.value = localStorage.getItem("een_token");
|
|
112
112
|
const s = localStorage.getItem("een_tokenExpiration");
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
a.value =
|
|
116
|
-
const
|
|
117
|
-
|
|
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
|
-
|
|
119
|
+
c("Failed to load from localStorage:", s instanceof Error ? s.message : String(s));
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
function
|
|
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
|
-
|
|
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:
|
|
132
|
+
tokenExpiration: n,
|
|
133
133
|
refreshTokenMarker: t,
|
|
134
|
-
sessionId:
|
|
134
|
+
sessionId: r,
|
|
135
135
|
hostname: o,
|
|
136
136
|
port: a,
|
|
137
|
-
userProfile:
|
|
138
|
-
isRefreshing:
|
|
139
|
-
refreshFailed:
|
|
140
|
-
refreshFailedMessage:
|
|
137
|
+
userProfile: i,
|
|
138
|
+
isRefreshing: I,
|
|
139
|
+
refreshFailed: _,
|
|
140
|
+
refreshFailedMessage: d,
|
|
141
141
|
// Computed
|
|
142
|
-
isAuthenticated:
|
|
143
|
-
baseUrl:
|
|
144
|
-
isTokenExpired:
|
|
145
|
-
tokenExpiresIn:
|
|
142
|
+
isAuthenticated: m,
|
|
143
|
+
baseUrl: k,
|
|
144
|
+
isTokenExpired: U,
|
|
145
|
+
tokenExpiresIn: A,
|
|
146
146
|
// Actions
|
|
147
|
-
setToken:
|
|
148
|
-
setRefreshTokenMarker:
|
|
149
|
-
setSessionId:
|
|
150
|
-
setBaseUrl:
|
|
151
|
-
setUserProfile:
|
|
152
|
-
setupAutoRefresh:
|
|
153
|
-
clearRefreshFailed:
|
|
154
|
-
logout:
|
|
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
|
-
}),
|
|
158
|
-
function
|
|
159
|
-
const e =
|
|
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
|
|
162
|
+
const n = crypto.randomUUID();
|
|
163
163
|
try {
|
|
164
|
-
sessionStorage.setItem("een_oauth_state",
|
|
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:
|
|
172
|
-
state:
|
|
171
|
+
redirect_uri: N(),
|
|
172
|
+
state: n
|
|
173
173
|
});
|
|
174
|
-
return
|
|
174
|
+
return c("Generated auth URL with state:", n), `${oe}?${t.toString()}`;
|
|
175
175
|
}
|
|
176
|
-
async function
|
|
177
|
-
const
|
|
178
|
-
if (!
|
|
179
|
-
return
|
|
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:
|
|
182
|
+
redirect_uri: N()
|
|
183
183
|
});
|
|
184
184
|
try {
|
|
185
|
-
const
|
|
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 (!
|
|
193
|
-
const a = await
|
|
194
|
-
return
|
|
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
|
|
197
|
-
return
|
|
198
|
-
} catch (
|
|
199
|
-
return
|
|
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
|
|
203
|
-
const e =
|
|
202
|
+
async function ie() {
|
|
203
|
+
const e = C();
|
|
204
204
|
if (!e)
|
|
205
|
-
return
|
|
206
|
-
const
|
|
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
|
-
|
|
212
|
-
const
|
|
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 (!
|
|
218
|
-
const a = await
|
|
219
|
-
return
|
|
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
|
|
222
|
-
return
|
|
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
|
|
224
|
+
return l("NETWORK_ERROR", `Failed to refresh token: ${String(t)}`);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
async function
|
|
228
|
-
const e =
|
|
227
|
+
async function se() {
|
|
228
|
+
const e = C();
|
|
229
229
|
if (!e)
|
|
230
|
-
return
|
|
231
|
-
const
|
|
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
|
-
|
|
237
|
-
const
|
|
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 (
|
|
243
|
-
const o = await
|
|
244
|
-
return
|
|
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
|
|
246
|
+
return c("Token revoked"), T(void 0);
|
|
247
247
|
} catch (t) {
|
|
248
|
-
return
|
|
248
|
+
return n.logout(), l("NETWORK_ERROR", `Failed to revoke token: ${String(t)}`);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
async function
|
|
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
|
|
259
|
-
if (!
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
return
|
|
265
|
-
const o = E(), a =
|
|
266
|
-
return o.setToken(a.accessToken, a.expiresIn), o.setRefreshTokenMarker("present"), o.setSessionId(a.sessionId), o.setBaseUrl(a.httpsBaseUrl),
|
|
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
|
|
269
|
-
if (e.length !==
|
|
268
|
+
function ue(e, n) {
|
|
269
|
+
if (e.length !== n.length)
|
|
270
270
|
return !1;
|
|
271
271
|
let t = 0;
|
|
272
|
-
for (let
|
|
273
|
-
t |= e.charCodeAt(
|
|
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
|
|
276
|
+
const ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
277
277
|
__proto__: null,
|
|
278
|
-
getAccessToken:
|
|
279
|
-
getAuthUrl:
|
|
280
|
-
handleAuthCallback:
|
|
281
|
-
refreshToken:
|
|
282
|
-
revokeToken:
|
|
278
|
+
getAccessToken: b,
|
|
279
|
+
getAuthUrl: ae,
|
|
280
|
+
handleAuthCallback: le,
|
|
281
|
+
refreshToken: ie,
|
|
282
|
+
revokeToken: se
|
|
283
283
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
284
|
-
async function
|
|
284
|
+
async function de() {
|
|
285
285
|
const e = E();
|
|
286
286
|
if (!e.isAuthenticated)
|
|
287
|
-
return
|
|
287
|
+
return l("AUTH_REQUIRED", "Authentication required");
|
|
288
288
|
if (!e.baseUrl)
|
|
289
|
-
return
|
|
290
|
-
const
|
|
291
|
-
|
|
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(
|
|
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
|
|
302
|
-
const
|
|
303
|
-
return
|
|
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
|
|
305
|
+
return l("NETWORK_ERROR", `Failed to fetch current user: ${String(t)}`);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
-
async function
|
|
309
|
-
const
|
|
310
|
-
if (!
|
|
311
|
-
return
|
|
312
|
-
if (!
|
|
313
|
-
return
|
|
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
|
|
317
|
-
|
|
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 ${
|
|
323
|
+
Authorization: `Bearer ${n.token}`
|
|
324
324
|
}
|
|
325
325
|
});
|
|
326
326
|
if (!a.ok)
|
|
327
|
-
return
|
|
328
|
-
const
|
|
329
|
-
return
|
|
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
|
|
331
|
+
return l("NETWORK_ERROR", `Failed to fetch users: ${String(a)}`);
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
async function
|
|
334
|
+
async function _e(e, n) {
|
|
335
335
|
const t = E();
|
|
336
336
|
if (!t.isAuthenticated)
|
|
337
|
-
return
|
|
337
|
+
return l("AUTH_REQUIRED", "Authentication required");
|
|
338
338
|
if (!t.baseUrl)
|
|
339
|
-
return
|
|
339
|
+
return l("AUTH_REQUIRED", "Base URL not configured");
|
|
340
340
|
if (!e)
|
|
341
|
-
return
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
const o =
|
|
345
|
-
|
|
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
|
|
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 (!
|
|
355
|
-
return
|
|
356
|
-
const
|
|
357
|
-
return
|
|
358
|
-
} catch (
|
|
359
|
-
return
|
|
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
|
|
363
|
-
const
|
|
362
|
+
async function L(e) {
|
|
363
|
+
const n = e.status;
|
|
364
364
|
let t;
|
|
365
365
|
try {
|
|
366
|
-
const
|
|
367
|
-
t =
|
|
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 (
|
|
371
|
+
switch (n) {
|
|
372
372
|
case 401:
|
|
373
|
-
return
|
|
373
|
+
return l("AUTH_REQUIRED", `Authentication failed: ${t}`, n);
|
|
374
374
|
case 403:
|
|
375
|
-
return
|
|
375
|
+
return l("FORBIDDEN", `Access denied: ${t}`, n);
|
|
376
376
|
case 404:
|
|
377
|
-
return
|
|
377
|
+
return l("NOT_FOUND", `Not found: ${t}`, n);
|
|
378
378
|
case 429:
|
|
379
|
-
return
|
|
379
|
+
return l("RATE_LIMITED", `Rate limited: ${t}`, n);
|
|
380
380
|
default:
|
|
381
|
-
return
|
|
381
|
+
return l("API_ERROR", `API error: ${t}`, n);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
|
-
function
|
|
385
|
-
const
|
|
386
|
-
t.value = !0,
|
|
387
|
-
const
|
|
388
|
-
return
|
|
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 &&
|
|
391
|
-
user:
|
|
390
|
+
return e?.immediate !== !1 && x(o), {
|
|
391
|
+
user: n,
|
|
392
392
|
loading: t,
|
|
393
|
-
error:
|
|
393
|
+
error: r,
|
|
394
394
|
fetch: o,
|
|
395
395
|
refresh: a
|
|
396
396
|
};
|
|
397
397
|
}
|
|
398
|
-
function
|
|
399
|
-
const t =
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
return
|
|
403
|
-
},
|
|
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
|
|
406
|
-
},
|
|
407
|
-
if (
|
|
408
|
-
return
|
|
409
|
-
},
|
|
410
|
-
|
|
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
|
|
412
|
+
return n?.immediate !== !1 && x(d), {
|
|
413
413
|
users: t,
|
|
414
|
-
loading:
|
|
414
|
+
loading: r,
|
|
415
415
|
error: o,
|
|
416
416
|
nextPageToken: a,
|
|
417
|
-
prevPageToken:
|
|
418
|
-
totalSize:
|
|
419
|
-
hasNextPage:
|
|
417
|
+
prevPageToken: i,
|
|
418
|
+
totalSize: f,
|
|
419
|
+
hasNextPage: I,
|
|
420
420
|
hasPrevPage: g,
|
|
421
|
-
params:
|
|
422
|
-
fetch:
|
|
423
|
-
refresh:
|
|
424
|
-
fetchNextPage:
|
|
425
|
-
fetchPrevPage:
|
|
426
|
-
setParams:
|
|
421
|
+
params: _,
|
|
422
|
+
fetch: d,
|
|
423
|
+
refresh: m,
|
|
424
|
+
fetchNextPage: k,
|
|
425
|
+
fetchPrevPage: U,
|
|
426
|
+
setParams: A
|
|
427
427
|
};
|
|
428
428
|
}
|
|
429
|
-
function
|
|
430
|
-
const t =
|
|
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
|
-
|
|
435
|
-
const
|
|
436
|
-
include:
|
|
437
|
-
...
|
|
438
|
-
},
|
|
439
|
-
return
|
|
440
|
-
},
|
|
441
|
-
return
|
|
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:
|
|
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:
|
|
446
|
-
refresh:
|
|
574
|
+
fetch: i,
|
|
575
|
+
refresh: f
|
|
447
576
|
};
|
|
448
577
|
}
|
|
449
578
|
export {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
pe as
|
|
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
|