@har-analyzer/components 0.0.16 → 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.
Files changed (45) hide show
  1. package/README.md +50 -25
  2. package/dist/chunks/collapsible-key-value-list.js +5 -5
  3. package/dist/chunks/content-viewer.js +146 -140
  4. package/dist/chunks/context.js +5 -0
  5. package/dist/chunks/index.js +588 -521
  6. package/dist/chunks/provider.js +11 -0
  7. package/dist/components/collapsible-section.d.ts +1 -1
  8. package/dist/components/enhanced-table.d.ts +10 -2
  9. package/dist/context/user-preferences/index.d.ts +6 -0
  10. package/dist/context/user-preferences/provider.d.ts +9 -0
  11. package/dist/context/user-preferences-store/context.d.ts +5 -0
  12. package/dist/context/user-preferences-store/hooks.d.ts +1 -0
  13. package/dist/context/user-preferences-store/provider.d.ts +5 -0
  14. package/dist/features/har-analyzer/components/app-layout.d.ts +7 -0
  15. package/dist/features/har-analyzer/components/preferences/index.d.ts +1 -0
  16. package/dist/features/har-analyzer/components/top-navigation.d.ts +8 -0
  17. package/dist/features/har-analyzer/context/preferences.d.ts +2 -0
  18. package/dist/features/har-analyzer-preferences-store/index.d.ts +2 -0
  19. package/dist/features/har-entries-viewer/index.d.ts +0 -1
  20. package/dist/features/list-har-entries/components/compare-mode-switcher.d.ts +1 -6
  21. package/dist/features/list-har-entries/components/content-type-filter.d.ts +1 -7
  22. package/dist/features/list-har-entries/components/errors-filter.d.ts +1 -6
  23. package/dist/features/list-har-entries/components/har-entries-table.d.ts +8 -0
  24. package/dist/features/list-har-entries/context/preferences.d.ts +5 -0
  25. package/dist/features/list-har-entries/index.d.ts +3 -9
  26. package/dist/har-analyzer-preferences-store.js +4 -0
  27. package/dist/har-analyzer.js +93 -87
  28. package/dist/har-entries-viewer.js +80 -79
  29. package/dist/index.d.ts +7 -1
  30. package/dist/index.js +9 -9
  31. package/dist/list-har-entries.js +2 -6
  32. package/dist/utils/har.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunks/json.js +0 -10
  35. package/dist/components/enhanced-top-navigation.d.ts +0 -7
  36. package/dist/components/simple-app-layout.d.ts +0 -6
  37. package/dist/components/simple-app-preferences/index.d.ts +0 -1
  38. package/dist/features/har-analyzer-preferences/index.d.ts +0 -7
  39. package/dist/features/list-har-entries/hooks/preferences.d.ts +0 -2
  40. package/dist/har-analyzer-preferences.js +0 -25
  41. package/dist/hooks/app-preferences.d.ts +0 -2
  42. package/dist/hooks/compare-mode-preference.d.ts +0 -1
  43. package/dist/hooks/table-preferences.d.ts +0 -12
  44. /package/dist/{components/simple-app-preferences → features/har-analyzer/components/preferences/components}/content-width-switcher.d.ts +0 -0
  45. /package/dist/{components/simple-app-preferences → features/har-analyzer/components/preferences/components}/theme-switcher.d.ts +0 -0
package/README.md CHANGED
@@ -13,7 +13,7 @@ Reusable React components for HAR Analyzer.
13
13
  - ⚖️ **Entry Comparison**: Compare multiple HAR entries side-by-side to easily spot differences in headers, payloads, and responses by simply selecting multiple rows in the network table.
14
14
  - 🔍 **Advanced Filtering**: Filter network entries quickly by content types (JSON, HTML, JS, CSS, etc.) or error statuses via `<HAREntriesFilters />`.
15
15
  - 🕵️ **Deep Inspection**: Inspect detailed request/response headers, decoded payloads, and syntax-highlighted response bodies with `<ViewHAREntry />`.
16
- - 🛠️ **Persistent Preferences**: Context providers remember user preferences like themes (dark/light mode) and table column layouts effortlessly via the `<HARAnalyzerPreferencesProvider />`.
16
+ - 🛠️ **Persistent Preferences**: Context providers remember user preferences like themes (dark/light mode) and table column layouts effortlessly via the `<HARAnalyzerPreferencesStore />`.
17
17
  - 🎨 **Cloudscape UI**: Built on top of the [Cloudscape Design System](https://cloudscape.design/).
18
18
  - ⌨️ **Type Safe**: Fully written in TypeScript with exported utility types (`HARContent`, `HAREntry`) for standard HTTP Archive structures.
19
19
 
@@ -43,25 +43,28 @@ npm install react react-dom \
43
43
 
44
44
  ## Usage & Setup
45
45
 
46
- Clients **must** wrap the components with `HARAnalyzerPreferencesProvider` (to handle user preferences like themes and table settings) and Cloudscape's `<I18nProvider>` (for localization).
46
+ Clients **must** wrap the components with `HARAnalyzerPreferencesStore` (to handle user preferences like themes and table settings) and Cloudscape's `<I18nProvider>` (for localization).
47
47
 
48
- ```jsx
48
+ ```tsx
49
49
  import enMessages from '@cloudscape-design/components/i18n/messages/all.en.js';
50
50
  import { I18nProvider } from '@cloudscape-design/components/i18n';
51
- import useLocalStorageState from 'use-local-storage-state';
52
51
  import HAREntriesViewer from '@har-analyzer/components/har-entries-viewer';
53
- import HARAnalyzerPreferencesProvider from '@har-analyzer/components/har-analyzer-preferences';
52
+ import HARAnalyzerPreferencesStore, { type UserPreferencesStore } from '@har-analyzer/components/har-analyzer-preferences-store';
54
53
 
55
- // Provide a custom usePreference hook conforming to:
56
- // (key: string) => readonly [string | undefined, (preference: string) => void]
57
- const useWebStorage = (key) => useLocalStorageState(key);
54
+ // Provide a store conforming to the UserPreferencesStore interface:
55
+ // getPreference: (key: string) => Promise<string | undefined>
56
+ // setPreference: (key: string, value: string) => Promise<void>
57
+ const myStorage: UserPreferencesStore = {
58
+ getPreference: async (key) => localStorage.getItem(key) || undefined,
59
+ setPreference: async (key, value) => localStorage.setItem(key, value),
60
+ };
58
61
 
59
62
  function App() {
60
63
  return (
61
64
  <I18nProvider locale="en" messages={[enMessages]}>
62
- <HARAnalyzerPreferencesProvider usePreferenceStore={useWebStorage}>
63
- <HAREntriesViewer tableId="my-report-table" harEntries={yourHarEntriesArray} />
64
- </HARAnalyzerPreferencesProvider>
65
+ <HARAnalyzerPreferencesStore userPreferencesStore={myStorage}>
66
+ <HAREntriesViewer tableTitle="My HAR Entries" harEntries={yourHarEntriesArray} />
67
+ </HARAnalyzerPreferencesStore>
65
68
  </I18nProvider>
66
69
  );
67
70
  }
@@ -75,7 +78,7 @@ The library supports both **top-level** imports and **component-level** imports.
75
78
  ```javascript
76
79
  import {
77
80
  HARAnalyzer,
78
- HARAnalyzerPreferencesProvider,
81
+ HARAnalyzerPreferencesStore,
79
82
  HAREntriesViewer,
80
83
  HARFileUploader,
81
84
  ListHAREntries,
@@ -86,7 +89,7 @@ import {
86
89
  **Component-level:**
87
90
  ```javascript
88
91
  import HARAnalyzer from '@har-analyzer/components/har-analyzer';
89
- import HARAnalyzerPreferencesProvider from '@har-analyzer/components/har-analyzer-preferences';
92
+ import HARAnalyzerPreferencesStore from '@har-analyzer/components/har-analyzer-preferences-store';
90
93
  import HAREntriesViewer from '@har-analyzer/components/har-entries-viewer';
91
94
  import HARFileUploader from '@har-analyzer/components/har-file-uploader';
92
95
  import ListHAREntries from '@har-analyzer/components/list-har-entries';
@@ -123,7 +126,7 @@ import HAREntriesViewer from '@har-analyzer/components/har-entries-viewer';
123
126
 
124
127
  function App() {
125
128
  return (
126
- <HAREntriesViewer tableId="har-viewer-table" harEntries={yourHarEntriesArray} />
129
+ <HAREntriesViewer tableTitle="Requests" harEntries={yourHarEntriesArray} />
127
130
  );
128
131
  }
129
132
  ```
@@ -133,7 +136,6 @@ function App() {
133
136
  | Name | Type | Required | Description |
134
137
  |---------------|-------------------------------|----------|--------------------------------------------------|
135
138
  | harEntries | HAREntry[] | Yes | An array of HAR entries. |
136
- | tableId | string | Yes | Unique identifier for the table component. |
137
139
  | tableTitle | string | No | Title of the table displaying the HAR entries. |
138
140
 
139
141
  ---
@@ -148,7 +150,7 @@ import ListHAREntries from '@har-analyzer/components/list-har-entries';
148
150
  function App() {
149
151
  return (
150
152
  <ListHAREntries
151
- id="my-table"
153
+ title="Requests"
152
154
  harEntries={yourHarEntriesArray}
153
155
  selectedHAREntries={[]}
154
156
  onSelectionChange={(entries) => console.log('Selected:', entries)}
@@ -161,7 +163,6 @@ function App() {
161
163
 
162
164
  | Name | Type | Required | Description |
163
165
  |---------------------|-------------------------------------------|----------|------------------------------------------|
164
- | id | string | Yes | Unique identifier for the list. |
165
166
  | title | string | No | Optional title for the list. |
166
167
  | harEntries | HAREntry[] | Yes | The entries to display in the table. |
167
168
  | selectedHAREntries | HAREntry[] | Yes | Entries to remain selected in the table. |
@@ -212,19 +213,23 @@ function App() {
212
213
 
213
214
  ---
214
215
 
215
- ### HARAnalyzerPreferencesProvider
216
+ ### HARAnalyzerPreferencesStore
216
217
 
217
- Provides a persistent context for managing user preferences (like theme, content width, table preferences and board layouts). You must wrap your application in `HARAnalyzerPreferencesProvider` and provide a `usePreferenceStore` hook that bridges external storage (like browser storage or Chrome Extensions API) into the library.
218
- ```jsx
219
- import HARAnalyzerPreferencesProvider from '@har-analyzer/components/har-analyzer-preferences';
218
+ Provides a persistent context for managing user preferences (like theme, content width, table preferences, and board layouts). You must wrap your application in `HARAnalyzerPreferencesStore` and provide a `userPreferencesStore` object that bridges external async storage (like browser storage APIs or Chrome Extensions API) into the library.
220
219
 
221
- const useWebStorage = (key) => useLocalStorageState(key);
220
+ ```tsx
221
+ import HARAnalyzerPreferencesStore, { type UserPreferencesStore } from '@har-analyzer/components/har-analyzer-preferences-store';
222
+
223
+ const myStorage: UserPreferencesStore = {
224
+ getPreference: async (key) => localStorage.getItem(key) || undefined,
225
+ setPreference: async (key, value) => { localStorage.setItem(key, value); }
226
+ };
222
227
 
223
228
  function App() {
224
229
  return (
225
- <HARAnalyzerPreferencesProvider usePreferenceStore={useWebStorage}>
230
+ <HARAnalyzerPreferencesStore userPreferencesStore={myStorage}>
226
231
  ...your HAR Analyzer components
227
- </HARAnalyzerPreferencesProvider>
232
+ </HARAnalyzerPreferencesStore>
228
233
  );
229
234
  }
230
235
  ```
@@ -238,11 +243,31 @@ Various types and utilities for working with HTTP Archive (.har) files are direc
238
243
  ```typescript
239
244
  import {
240
245
  getHARContentFromFile,
246
+ getHAREntriesFilteredByContentType,
247
+ getHAREntriesWithErrorResponse,
248
+ getHAREntryId,
249
+ isErrorResponse,
241
250
  type HARContent,
242
- type HAREntry
251
+ type HAREntry,
252
+ type ContentTypeGroup
243
253
  } from '@har-analyzer/components';
244
254
  ```
245
255
 
256
+ ### `getHARContentFromFile(fileContent: unknown): HARContent`
257
+ Parses a JSON string into a structured `HARContent` object. Throws an error if the content is not a valid JSON string.
258
+
259
+ ### `getHAREntriesFilteredByContentType(harEntries: HAREntry[], contentTypeFilters: ContentTypeGroup[]): HAREntry[]`
260
+ Filters an array of HAR entries by their response MIME types mapped to high-level content type groups (e.g., `'JSON'`, `'XML'`, `'JS'`, `'CSS'`, `'HTML'`, `'Doc'`, `'Img'`, `'Font'`, `'Media'`, `'Other'`).
261
+
262
+ ### `isErrorResponse(harEntry: HAREntry): boolean`
263
+ Returns `true` if the HAR entry's response has a status code less than 200 or greater than or equal to 400.
264
+
265
+ ### `getHAREntriesWithErrorResponse(harEntries: HAREntry[]): HAREntry[]`
266
+ Returns a filtered array of HAR entries containing only those that resulted in an error (based on `isErrorResponse`).
267
+
268
+ ### `getHAREntryId(harEntry: HAREntry): string`
269
+ Generates a unique deterministic ID for a given HAR entry using a combination of `startedDateTime`, `time`, and `request.url`.
270
+
246
271
  ---
247
272
 
248
273
  ## Development
@@ -3,21 +3,21 @@ import n from "@cloudscape-design/components/box";
3
3
  import p from "@cloudscape-design/components/column-layout";
4
4
  import { C as a } from "./collapsible-section.js";
5
5
  import s from "@cloudscape-design/components/copy-to-clipboard";
6
- function u(t) {
7
- const { textToCopy: e, textToDisplay: r } = t;
6
+ function u(i) {
7
+ const { textToCopy: t, textToDisplay: r } = i;
8
8
  return /* @__PURE__ */ o(
9
9
  s,
10
10
  {
11
11
  variant: "inline",
12
- textToCopy: e,
12
+ textToCopy: t,
13
13
  textToDisplay: r,
14
14
  copyErrorText: "Failed to copy",
15
15
  copySuccessText: "Copied!"
16
16
  }
17
17
  );
18
18
  }
19
- function x({ title: t, items: e = [] }) {
20
- return /* @__PURE__ */ o(a, { title: t, children: /* @__PURE__ */ o(p, { borders: "horizontal", columns: 2, disableGutters: !0, children: e.reduce((r, { name: l, value: i }) => (r.push(/* @__PURE__ */ o(n, { variant: "awsui-key-label", children: l })), r.push(i ? /* @__PURE__ */ o(u, { textToCopy: i }) : /* @__PURE__ */ o(n, { variant: "span", children: "-" })), r), []) }) });
19
+ function x({ title: i, items: t = [] }) {
20
+ return /* @__PURE__ */ o(a, { variant: "inline", title: i, children: /* @__PURE__ */ o(p, { borders: "horizontal", columns: 2, disableGutters: !0, children: t.reduce((r, { name: l, value: e }) => (r.push(/* @__PURE__ */ o(n, { variant: "awsui-key-label", children: l })), r.push(e ? /* @__PURE__ */ o(u, { textToCopy: e }) : /* @__PURE__ */ o(n, { variant: "span", children: "-" })), r), []) }) });
21
21
  }
22
22
  export {
23
23
  x as C