@har-analyzer/components 0.0.5 → 0.0.9

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.
@@ -1,13 +1,16 @@
1
- import type { Har } from 'har-format';
1
+ import { Har } from 'har-format';
2
2
  import { JSX } from 'react/jsx-runtime';
3
3
 
4
- declare type HarContent = Har;
4
+ declare type HARContent = Har;
5
5
 
6
6
  declare function HARFileUploader({ onChange }: HARFileUploaderProps): JSX.Element;
7
7
  export default HARFileUploader;
8
8
 
9
9
  declare interface HARFileUploaderProps {
10
- onChange: (harContent: HarContent, harFileName?: string) => void;
10
+ onChange: (args: {
11
+ harContent: HARContent;
12
+ harFileName?: string;
13
+ }) => void;
11
14
  }
12
15
 
13
16
  export { }
@@ -1,8 +1,75 @@
1
- import "./chunks/content-type.js";
2
- import "./chunks/vertical-gap.js";
3
- import { H as a } from "./chunks/index3.js";
4
- import "react";
5
- import "./chunks/index4.js";
1
+ import { jsx as a, jsxs as u } from "react/jsx-runtime";
2
+ import f from "@cloudscape-design/components/box";
3
+ import p from "@cloudscape-design/components/file-dropzone";
4
+ import g from "@cloudscape-design/components/file-input";
5
+ import { useState as F } from "react";
6
+ import { V as d } from "./chunks/vertical-gap.js";
7
+ import { g as E } from "./chunks/har.js";
8
+ import w from "@cloudscape-design/components/flashbar";
9
+ const c = ".har";
10
+ function C(r) {
11
+ return r ? r.name.toLowerCase().endsWith(c) : !1;
12
+ }
13
+ function A(r) {
14
+ return r.length !== 1;
15
+ }
16
+ function x(r) {
17
+ const o = [];
18
+ return A(r) && o.push("You can only upload one file at a time"), C(r[0]) || o.push(`Only files with the "${c}" extension are allowed`), o;
19
+ }
20
+ function y(r) {
21
+ return new Promise((o, e) => {
22
+ if (!r) {
23
+ e(new Error("No HAR file provided"));
24
+ return;
25
+ }
26
+ const i = new FileReader();
27
+ i.onload = (n) => {
28
+ try {
29
+ const s = n.target?.result;
30
+ o(s);
31
+ } catch (s) {
32
+ console.error("Failed to JSON parse file content:", s), e(new Error("errorMessage"));
33
+ }
34
+ }, i.onerror = () => {
35
+ e(new Error("Error reading HAR file"));
36
+ }, i.readAsText(r);
37
+ });
38
+ }
39
+ function R({ errors: r }) {
40
+ const o = r.map((e) => ({
41
+ type: "error",
42
+ content: e,
43
+ id: e
44
+ }));
45
+ return /* @__PURE__ */ a(w, { items: o });
46
+ }
47
+ function P({ onChange: r }) {
48
+ const [o, e] = F([]), i = async (n) => {
49
+ e([]);
50
+ const s = x(n);
51
+ if (s.length > 0) {
52
+ e(s);
53
+ return;
54
+ }
55
+ try {
56
+ const t = n[0], l = t?.name, h = await y(t), m = E(h);
57
+ r({ harContent: m, harFileName: l });
58
+ } catch (t) {
59
+ console.error("Error reading HAR file:", t);
60
+ const l = t instanceof Error ? t.message : "An unknown error occurred";
61
+ e([l]);
62
+ }
63
+ };
64
+ return /* @__PURE__ */ u(d, { children: [
65
+ /* @__PURE__ */ a(R, { errors: o }),
66
+ /* @__PURE__ */ a(p, { onChange: ({ detail: n }) => i(n.value), children: /* @__PURE__ */ u(d, { alignItems: "center", size: "s", children: [
67
+ /* @__PURE__ */ a(f, { color: "inherit", children: "Drop your .har file here" }),
68
+ /* @__PURE__ */ a(f, { color: "inherit", children: "or" }),
69
+ /* @__PURE__ */ a(g, { accept: c, value: [], onChange: ({ detail: n }) => i(n.value), children: "Choose file" })
70
+ ] }) })
71
+ ] });
72
+ }
6
73
  export {
7
- a as default
74
+ P as default
8
75
  };
package/dist/index.d.ts CHANGED
@@ -1,29 +1,44 @@
1
- import type { Har } from 'har-format';
1
+ import { Entry } from 'har-format';
2
+ import { Har } from 'har-format';
2
3
  import { JSX } from 'react/jsx-runtime';
4
+ import { PropsWithChildren } from 'react';
3
5
 
4
- declare function getEntriesFromHAR(harContent?: Har) {
5
- return harContent?.log.entries || [];
6
- }
6
+ declare const CONTENT_TYPE_GROUPS: readonly [...("JSON" | "XML" | "JS" | "CSS" | "HTML" | "Doc" | "Img" | "Font" | "Media")[], "Other"];
7
+
8
+ declare type ContentTypeGroup = (typeof CONTENT_TYPE_GROUPS)[number];
9
+
10
+ export declare function getEntriesFromHAR(harContent?: Har): Entry[];
11
+
12
+ export declare function getHARContentFromFile(fileContent: unknown): HARContent;
13
+
14
+ export declare function getHAREntriesFilteredByContentType(harEntries: HAREntry[], contentTypeFilters: ContentTypeGroup[]): HAREntry[];
15
+
16
+ export declare function getHAREntriesWithErrorResponse(harEntries: HAREntry[]): HAREntry[];
17
+
18
+ export declare function getUniqueHeaderNames(harEntries: HAREntry[], type: 'request' | 'response'): string[];
7
19
 
8
- export declare function HarAnalyzer({ logo, appName }: HarAnalyzerProps): JSX.Element;
20
+ export declare function HARAnalyzer({ logo, appName }: HARAnalyzerProps): JSX.Element;
9
21
 
10
- declare interface HarAnalyzerProps {
22
+ export declare function HARAnalyzerPreferencesProvider({ store, children }: PropsWithChildren<{
23
+ store: UserPreferenceStore;
24
+ }>): JSX.Element;
25
+
26
+ declare interface HARAnalyzerProps {
11
27
  logo?: React.ReactNode;
12
- appName: string;
28
+ appName?: string;
13
29
  }
14
30
 
15
- declare type HarContent = Har;
31
+ export declare type HARContent = Har;
16
32
 
17
- export declare function HAREntriesViewer({ harFileName, harContent, onChange }: HAREntriesViewerProps): JSX.Element | undefined;
33
+ export declare function HARContentViewer(props: HARContentViewerProps): JSX.Element;
18
34
 
19
- declare interface HAREntriesViewerProps {
20
- harFileName?: string;
21
- harContent?: HarContent;
22
- onChange: (selectedHAREntry: HAREntry) => void;
35
+ declare interface HARContentViewerProps {
36
+ harFileName: string;
37
+ harContent: HARContent;
23
38
  }
24
39
 
25
- declare type HAREntry = Omit<HAREntryWithoutError, 'response'> & {
26
- response: HARResponseWithError;
40
+ export declare type HAREntry = Omit<HAREntryWithoutError, 'response'> & {
41
+ response: HARResponseWithError;
27
42
  };
28
43
 
29
44
  export declare function HAREntryViewer({ harEntry }: HAREntryViewerProps): JSX.Element;
@@ -37,9 +52,26 @@ declare type HAREntryWithoutError = ReturnType<typeof getEntriesFromHAR>[number]
37
52
  export declare function HARFileUploader({ onChange }: HARFileUploaderProps): JSX.Element;
38
53
 
39
54
  declare interface HARFileUploaderProps {
40
- onChange: (harContent: HarContent, harFileName?: string) => void;
55
+ onChange: (args: {
56
+ harContent: HARContent;
57
+ harFileName?: string;
58
+ }) => void;
41
59
  }
42
60
 
43
- declare type HARResponseWithError = HAREntryWithoutError['response'] & { _error?: string };
61
+ declare type HARResponseWithError = HAREntryWithoutError['response'] & {
62
+ _error?: string;
63
+ };
64
+
65
+ export declare function isErrorResponse(harEntry: HAREntry): boolean;
66
+
67
+ export declare function useHAREntriesFilters(harEntries: HAREntry[]): {
68
+ filteredHAREntries: HAREntry[];
69
+ HAREntriesFilters: () => JSX.Element;
70
+ };
71
+
72
+ declare interface UserPreferenceStore {
73
+ getPreference: (key: string) => Promise<string | undefined>;
74
+ setPreference: (key: string, value: string) => Promise<void>;
75
+ }
44
76
 
45
77
  export { }
package/dist/index.js CHANGED
@@ -1,10 +1,21 @@
1
- import { default as o } from "./har-analyzer.js";
2
- import { H as t } from "./chunks/index.js";
3
- import { H as f } from "./chunks/index2.js";
4
- import { H as s } from "./chunks/index3.js";
1
+ import { default as t } from "./har-analyzer.js";
2
+ import { default as s } from "./har-analyzer-preferences.js";
3
+ import { default as n } from "./har-content-viewer.js";
4
+ import { u as f } from "./chunks/index.js";
5
+ import { default as A } from "./har-entry-viewer.js";
6
+ import { default as p } from "./har-file-uploader.js";
7
+ import { a as d, g as m, b as u, c as x, d as E, i as g } from "./chunks/har.js";
5
8
  export {
6
- t as HAREntriesViewer,
7
- f as HAREntryViewer,
8
- s as HARFileUploader,
9
- o as HarAnalyzer
9
+ t as HARAnalyzer,
10
+ s as HARAnalyzerPreferencesProvider,
11
+ n as HARContentViewer,
12
+ A as HAREntryViewer,
13
+ p as HARFileUploader,
14
+ d as getEntriesFromHAR,
15
+ m as getHARContentFromFile,
16
+ u as getHAREntriesFilteredByContentType,
17
+ x as getHAREntriesWithErrorResponse,
18
+ E as getUniqueHeaderNames,
19
+ g as isErrorResponse,
20
+ f as useHAREntriesFilters
10
21
  };
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@har-analyzer/components",
3
- "version": "0.0.5",
3
+ "type": "module",
4
+ "version": "0.0.9",
4
5
  "description": "Reusable React components for HAR Analyzer",
5
6
  "author": "Allan Joshua",
6
7
  "license": "MIT",
8
+ "homepage": "https://github.com/theallanjoshua/har-analyzer/tree/main/packages/components#readme",
7
9
  "repository": {
8
10
  "type": "git",
9
11
  "url": "https://github.com/theallanjoshua/har-analyzer.git",
10
12
  "directory": "packages/components"
11
13
  },
12
- "homepage": "https://github.com/theallanjoshua/har-analyzer/tree/main/packages/components#readme",
13
14
  "bugs": {
14
15
  "url": "https://github.com/theallanjoshua/har-analyzer/issues"
15
16
  },
@@ -20,39 +21,35 @@
20
21
  "har file viewer"
21
22
  ],
22
23
  "publishConfig": {
23
- "access": "public"
24
- },
25
- "type": "module",
26
- "files": [
27
- "dist"
28
- ],
29
- "main": "dist/index.js",
30
- "types": "dist/index.d.ts",
24
+ "access": "public"
25
+ },
31
26
  "exports": {
32
27
  ".": {
33
- "import": "./dist/index.js",
34
- "types": "./dist/index.d.ts"
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
35
30
  },
36
31
  "./*": {
37
- "import": "./dist/*.js",
38
- "types": "./dist/*.d.ts"
32
+ "types": "./dist/*.d.ts",
33
+ "import": "./dist/*.js"
39
34
  }
40
35
  },
36
+ "main": "dist/index.js",
37
+ "types": "dist/index.d.ts",
38
+ "files": [
39
+ "dist"
40
+ ],
41
41
  "scripts": {
42
- "lint": "biome check",
43
- "dev": "concurrently -k \"tsc --emitDeclarationOnly --watch\" \"vite build --watch\"",
44
- "build": "tsc && vite build",
45
- "prepublishOnly": "pnpm run lint && pnpm run build"
46
- },
47
- "dependencies": {
48
- "buffer": "^6.0.3",
49
- "date-fns": "^4.1.0",
50
- "date-fns-tz": "^3.2.0",
51
- "pretty-bytes": "^7.0.0",
52
- "react-error-boundary": "^6.0.0",
53
- "use-local-storage-state": "^19.5.0"
42
+ "clean": "rm -rf dist",
43
+ "lint": "eslint",
44
+ "lint:fix": "eslint --fix",
45
+ "check-types": "tsc --noEmit",
46
+ "dev": "vite build --watch",
47
+ "build": "vite build",
48
+ "validate": "pnpm clean && pnpm lint && pnpm check-types && pnpm build",
49
+ "prepublishOnly": "pnpm validate"
54
50
  },
55
51
  "peerDependencies": {
52
+ "@cloudscape-design/board-components": "^3.0.150",
56
53
  "@cloudscape-design/code-view": "^3.0.66",
57
54
  "@cloudscape-design/collection-hooks": "^1.0.73",
58
55
  "@cloudscape-design/components": "^3.0.1022",
@@ -60,5 +57,13 @@
60
57
  "@cloudscape-design/global-styles": "^1.0.44",
61
58
  "react": "^19.1.0",
62
59
  "react-dom": "^19.1.0"
60
+ },
61
+ "dependencies": {
62
+ "buffer": "^6.0.3",
63
+ "date-fns": "^4.1.0",
64
+ "date-fns-tz": "^3.2.0",
65
+ "local-db-storage": "^2.0.0",
66
+ "pretty-bytes": "^7.0.0",
67
+ "react-error-boundary": "^6.0.0"
63
68
  }
64
69
  }