@har-analyzer/components 0.0.9 → 0.0.10
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.
|
@@ -4,15 +4,15 @@ import { PropsWithChildren } from 'react';
|
|
|
4
4
|
import { SetStateAction } from 'react';
|
|
5
5
|
|
|
6
6
|
declare function HARAnalyzerPreferencesProvider({ store, children }: PropsWithChildren<{
|
|
7
|
-
store:
|
|
7
|
+
store: PreferencesStore;
|
|
8
8
|
}>): JSX.Element;
|
|
9
9
|
export default HARAnalyzerPreferencesProvider;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare interface UserPreferenceStore {
|
|
11
|
+
declare interface PreferencesStore {
|
|
14
12
|
getPreference: (key: string) => Promise<string | undefined>;
|
|
15
13
|
setPreference: (key: string, value: string) => Promise<void>;
|
|
16
14
|
}
|
|
17
15
|
|
|
16
|
+
export declare function useHARAnalyzerPreferences<T>(preferenceKey: string, defaultValue: T): readonly [T, Dispatch<SetStateAction<T>>];
|
|
17
|
+
|
|
18
18
|
export { }
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
function
|
|
4
|
-
try {
|
|
5
|
-
return JSON.parse(t ?? "");
|
|
6
|
-
} catch (r) {
|
|
7
|
-
return console.warn("Failed to parse JSON string:", t, "Error:", r), e;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
async function i(t, e) {
|
|
1
|
+
import { jsx as D } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as E, use as F, useMemo as x, useState as A, useCallback as m, useEffect as b } from "react";
|
|
3
|
+
async function c(t, e) {
|
|
11
4
|
return new Promise((r, n) => {
|
|
12
5
|
t.addEventListener("success", () => {
|
|
13
6
|
r(t.result);
|
|
@@ -16,82 +9,88 @@ async function i(t, e) {
|
|
|
16
9
|
});
|
|
17
10
|
});
|
|
18
11
|
}
|
|
19
|
-
var
|
|
12
|
+
var S = function(t, e, r, n, a) {
|
|
20
13
|
if (n === "m") throw new TypeError("Private method is not writable");
|
|
21
|
-
if (n === "a" && !
|
|
22
|
-
if (typeof e == "function" ? t !== e || !
|
|
23
|
-
return n === "a" ?
|
|
24
|
-
},
|
|
14
|
+
if (n === "a" && !a) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
+
if (typeof e == "function" ? t !== e || !a : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
16
|
+
return n === "a" ? a.call(t, r) : a ? a.value = r : e.set(t, r), r;
|
|
17
|
+
}, o = function(t, e, r, n) {
|
|
25
18
|
if (r === "a" && !n) throw new TypeError("Private accessor was defined without a getter");
|
|
26
19
|
if (typeof e == "function" ? t !== e || !n : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
27
20
|
return r === "m" ? n : r === "a" ? n.call(t) : n ? n.value : e.get(t);
|
|
28
|
-
}, s, l,
|
|
29
|
-
class
|
|
21
|
+
}, s, l, i, d, g, _;
|
|
22
|
+
class C {
|
|
30
23
|
constructor({ name: e }) {
|
|
31
|
-
s.add(this), l.set(this, void 0),
|
|
24
|
+
s.add(this), l.set(this, void 0), i.set(this, void 0), S(this, l, e, "f");
|
|
32
25
|
}
|
|
33
26
|
async getItem(e) {
|
|
34
|
-
const r = await
|
|
35
|
-
return
|
|
27
|
+
const r = await o(this, s, "m", d).call(this);
|
|
28
|
+
return c(r.get(e), "Failed to get item");
|
|
36
29
|
}
|
|
37
30
|
async setItem(e, r) {
|
|
38
|
-
const n = await
|
|
39
|
-
return
|
|
31
|
+
const n = await o(this, s, "m", d).call(this);
|
|
32
|
+
return c(n.put(r, e), "Failed to set item");
|
|
40
33
|
}
|
|
41
34
|
async removeItem(e) {
|
|
42
|
-
const r = await
|
|
43
|
-
return
|
|
35
|
+
const r = await o(this, s, "m", d).call(this);
|
|
36
|
+
return c(r.delete(e), "Failed to remove item");
|
|
44
37
|
}
|
|
45
38
|
async clear() {
|
|
46
|
-
const e = await
|
|
47
|
-
return
|
|
39
|
+
const e = await o(this, s, "m", d).call(this);
|
|
40
|
+
return c(e.clear(), "Failed to clear store");
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
|
-
l = /* @__PURE__ */ new WeakMap(),
|
|
51
|
-
return (await
|
|
52
|
-
}, b = async function() {
|
|
53
|
-
return a(this, c, "f") === void 0 && y(this, c, a(this, s, "m", g).call(this), "f"), a(this, c, "f");
|
|
43
|
+
l = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakSet(), d = async function() {
|
|
44
|
+
return (await o(this, s, "m", g).call(this)).transaction("store", "readwrite").objectStore("store");
|
|
54
45
|
}, g = async function() {
|
|
55
|
-
|
|
46
|
+
return o(this, i, "f") === void 0 && S(this, i, o(this, s, "m", _).call(this), "f"), o(this, i, "f");
|
|
47
|
+
}, _ = async function() {
|
|
48
|
+
const e = indexedDB.open(o(this, l, "f"), 1);
|
|
56
49
|
return e.addEventListener("upgradeneeded", () => {
|
|
57
50
|
e.result.createObjectStore("store");
|
|
58
|
-
}),
|
|
51
|
+
}), c(e, "Failed to open IndexedDB");
|
|
59
52
|
};
|
|
60
|
-
const
|
|
61
|
-
get: async (t) => await
|
|
53
|
+
const p = new C({ name: "node_modules/local-db-storage" }), y = {
|
|
54
|
+
get: async (t) => await p.getItem(t),
|
|
62
55
|
set: async (t, e) => {
|
|
63
|
-
await
|
|
56
|
+
await p.setItem(t, e);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function I(t, e) {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(t ?? "");
|
|
62
|
+
} catch (r) {
|
|
63
|
+
return console.warn("Failed to parse JSON string:", t, "Error:", r), e;
|
|
64
64
|
}
|
|
65
|
-
}, P = D(void 0);
|
|
66
|
-
function T({ store: t, children: e }) {
|
|
67
|
-
return /* @__PURE__ */ v(P, { value: t, children: e });
|
|
68
65
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const P = E(void 0);
|
|
67
|
+
function L({ store: t, children: e }) {
|
|
68
|
+
return /* @__PURE__ */ D(P, { value: t, children: e });
|
|
69
|
+
}
|
|
70
|
+
const O = {
|
|
71
|
+
getPreference: y.get,
|
|
72
|
+
setPreference: y.set
|
|
72
73
|
};
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}, [f]);
|
|
83
|
-
const w = h(async () => {
|
|
74
|
+
function R(t, e) {
|
|
75
|
+
const r = F(P), n = x(() => r || (console.warn("Invoked outside of HARAnalyzerPreferencesProvider. Falling back to use fallback preferences store."), O), [r]), [a, f] = A(e), w = m(async () => {
|
|
76
|
+
const u = await n.getPreference(t), v = I(u, e);
|
|
77
|
+
f(v);
|
|
78
|
+
}, [n, t, e]);
|
|
79
|
+
b(() => {
|
|
80
|
+
w();
|
|
81
|
+
}, [w]);
|
|
82
|
+
const h = m(async () => {
|
|
84
83
|
try {
|
|
85
|
-
await
|
|
84
|
+
await n.setPreference(t, JSON.stringify(a));
|
|
86
85
|
} catch (u) {
|
|
87
86
|
console.error(`Failed to update preference for key ${t}:`, u);
|
|
88
87
|
}
|
|
89
|
-
}, [
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
}, [
|
|
88
|
+
}, [n, t, a]);
|
|
89
|
+
return b(() => {
|
|
90
|
+
h();
|
|
91
|
+
}, [h]), [a, f];
|
|
93
92
|
}
|
|
94
93
|
export {
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
L as default,
|
|
95
|
+
R as useHARAnalyzerPreferences
|
|
97
96
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function getUniqueHeaderNames(harEntries: HAREntry[], type: 'requ
|
|
|
20
20
|
export declare function HARAnalyzer({ logo, appName }: HARAnalyzerProps): JSX.Element;
|
|
21
21
|
|
|
22
22
|
export declare function HARAnalyzerPreferencesProvider({ store, children }: PropsWithChildren<{
|
|
23
|
-
store:
|
|
23
|
+
store: PreferencesStore;
|
|
24
24
|
}>): JSX.Element;
|
|
25
25
|
|
|
26
26
|
declare interface HARAnalyzerProps {
|
|
@@ -64,14 +64,14 @@ declare type HARResponseWithError = HAREntryWithoutError['response'] & {
|
|
|
64
64
|
|
|
65
65
|
export declare function isErrorResponse(harEntry: HAREntry): boolean;
|
|
66
66
|
|
|
67
|
+
declare interface PreferencesStore {
|
|
68
|
+
getPreference: (key: string) => Promise<string | undefined>;
|
|
69
|
+
setPreference: (key: string, value: string) => Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
|
|
67
72
|
export declare function useHAREntriesFilters(harEntries: HAREntry[]): {
|
|
68
73
|
filteredHAREntries: HAREntry[];
|
|
69
74
|
HAREntriesFilters: () => JSX.Element;
|
|
70
75
|
};
|
|
71
76
|
|
|
72
|
-
declare interface UserPreferenceStore {
|
|
73
|
-
getPreference: (key: string) => Promise<string | undefined>;
|
|
74
|
-
setPreference: (key: string, value: string) => Promise<void>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
77
|
export { }
|