@box/box-ai-agent-selector 0.40.1 → 0.40.3

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.
@@ -4629,7 +4629,7 @@ function zc({
4629
4629
  formatMessage: f
4630
4630
  } = bi(), [c, l] = X(!1), p = o === fn.ERROR, [b, v] = X(p), [x, w] = Ei(Si), P = wi(), g = o === fn.SUCCESS, m = o === fn.IN_PROGRESS, y = f(Qe.selectAgent), C = f(Qe.defaultAgent);
4631
4631
  let O = "";
4632
- g ? O = (u == null ? void 0 : u.name) || y : p && (O = C);
4632
+ g ? O = (u == null ? void 0 : u.name) ?? y : p && (O = C);
4633
4633
  const A = Y(null), {
4634
4634
  Wrapper: S,
4635
4635
  wrapperProps: T
@@ -1,24 +1,37 @@
1
- import { renderHook as n, act as c } from "@testing-library/react";
2
- import l from "../useLocalStorageAIAgents.js";
1
+ import { renderHook as l, act as d } from "@testing-library/react";
2
+ import c from "../useLocalStorageAIAgents.js";
3
3
  describe("useLocalStorageAIAgents", () => {
4
- const t = "testAgentKey", a = "agent-456";
5
- let u, i, d;
6
- beforeEach(() => {
7
- u = jest.spyOn(Storage.prototype, "setItem"), i = jest.spyOn(Storage.prototype, "getItem"), d = jest.spyOn(Storage.prototype, "removeItem"), localStorage.clear();
4
+ const o = "testAgentKey", r = "agent-456";
5
+ let a = {};
6
+ const g = jest.fn((e) => a[e]);
7
+ let u = jest.fn((e, t) => {
8
+ a[e] = t;
9
+ });
10
+ const i = jest.fn((e) => {
11
+ delete a[e];
12
+ });
13
+ Object.defineProperty(window, "localStorage", {
14
+ value: {
15
+ getItem: (e) => g(e),
16
+ setItem: (e, t) => u(e, t),
17
+ removeItem: (e) => i(e)
18
+ }
19
+ }), beforeEach(() => {
20
+ a = {};
8
21
  }), afterEach(() => {
9
22
  jest.clearAllMocks();
10
23
  }), test("should initialize with null when localStorage is empty", () => {
11
24
  const {
12
25
  result: e
13
- } = n(() => l(t)), [o] = e.current;
14
- expect(o).toBeNull(), expect(i).toHaveBeenCalledWith(t);
26
+ } = l(() => c(o)), [t] = e.current;
27
+ expect(t).toBeNull(), expect(g(o)).toBeUndefined();
15
28
  }), test("should initialize with value from localStorage if it exists and is valid", () => {
16
29
  const e = "agent-123";
17
- localStorage.setItem(t, e);
30
+ a[o] = e;
18
31
  const {
19
- result: o
20
- } = n(() => l(t)), [r] = o.current;
21
- expect(r).toBe(e), expect(i).toHaveBeenCalledWith(t);
32
+ result: t
33
+ } = l(() => c(o)), [n] = t.current;
34
+ expect(n).toBe(e), expect(g).toHaveBeenCalledWith(o);
22
35
  }), test("should return null if localStorage value contains invalid characters", () => {
23
36
  [
24
37
  `><script>alert('XSS Attack!');<\/script><div class="`,
@@ -27,48 +40,60 @@ describe("useLocalStorageAIAgents", () => {
27
40
  "${process.env.SECRET_KEY}",
28
41
  "../../../etc/passwd",
29
42
  "agent@123!"
30
- ].forEach((o) => {
31
- localStorage.setItem(t, o);
43
+ ].forEach((t) => {
44
+ a[o] = t;
32
45
  const {
33
- result: r
34
- } = n(() => l(t)), [s] = r.current;
35
- expect(s).toBeNull(), expect(d).toHaveBeenCalledWith(t);
46
+ result: n
47
+ } = l(() => c(o)), [s] = n.current;
48
+ expect(s).toBeNull(), expect(i).toHaveBeenCalledWith(o);
36
49
  });
37
50
  }), test("should update localStorage when state changes", () => {
38
51
  const {
39
52
  result: e,
40
- rerender: o
41
- } = n(() => l(t));
42
- let [r, s] = e.current;
43
- expect(r).not.toBe(a), c(() => {
44
- s(a);
45
- }), o(), [r] = e.current, expect(r).toBe(a), expect(u).toHaveBeenCalledWith(t, a);
53
+ rerender: t
54
+ } = l(() => c(o));
55
+ let [n, s] = e.current;
56
+ expect(n).not.toBe(r), d(() => {
57
+ s(r);
58
+ }), t(), [n] = e.current, expect(n).toBe(r), expect(u).toHaveBeenCalledWith(o, r);
46
59
  }), test("should remove localStorage item when setting to null", () => {
47
60
  const {
48
61
  result: e,
49
- rerender: o
50
- } = n(() => l(t));
51
- let [r, s] = e.current;
52
- expect(r).toBeNull(), c(() => {
53
- s(a);
54
- }), o(), [r] = e.current, expect(r).toBe(a), c(() => {
62
+ rerender: t
63
+ } = l(() => c(o));
64
+ let [n, s] = e.current;
65
+ expect(n).toBeNull(), d(() => {
66
+ s(r);
67
+ }), t(), [n] = e.current, expect(n).toBe(r), d(() => {
55
68
  s(null);
56
- }), o(), [r] = e.current, expect(r).toBeNull(), expect(d).toHaveBeenCalledWith(t);
69
+ }), t(), [n] = e.current, expect(n).toBeNull(), expect(i).toHaveBeenCalledWith(o);
57
70
  }), test("should handle valid alphanumeric characters with underscores and hyphens", () => {
58
71
  const e = "valid-agent_123", {
59
- result: o,
60
- rerender: r
61
- } = n(() => l(t)), [, s] = o.current;
62
- c(() => {
72
+ result: t,
73
+ rerender: n
74
+ } = l(() => c(o)), [, s] = t.current;
75
+ d(() => {
63
76
  s(e);
64
- }), r();
65
- const [g] = o.current;
66
- expect(g).toBe(e), expect(u).toHaveBeenCalledWith(t, e);
77
+ }), n();
78
+ const [h] = t.current;
79
+ expect(h).toBe(e), expect(u).toHaveBeenCalledWith(o, e);
67
80
  }), test("should return null for whitespace-only values in localStorage", () => {
68
- localStorage.setItem(t, " ");
81
+ a[o] = " ";
69
82
  const {
70
83
  result: e
71
- } = n(() => l(t)), [o] = e.current;
72
- expect(o).toBeNull();
84
+ } = l(() => c(o)), [t] = e.current;
85
+ expect(t).toBeNull();
86
+ }), test("should keep agent selection when localStorage full", () => {
87
+ u = jest.fn((h, p) => {
88
+ throw new Error("Quota exceeded");
89
+ });
90
+ const {
91
+ result: e,
92
+ rerender: t
93
+ } = l(() => c(o));
94
+ let [n, s] = e.current;
95
+ expect(n).not.toBe(r), d(() => {
96
+ s(r);
97
+ }), t(), [n] = e.current, expect(n).toBe(r), expect(u).toHaveBeenCalledWith(o, r), expect(i).toHaveBeenCalledWith(o);
73
98
  });
74
99
  });
@@ -1,21 +1,28 @@
1
- import { useState as l, useEffect as s } from "react";
2
- const c = (e, o = !0) => {
3
- const [t, a] = l(() => {
1
+ import { useState as l, useEffect as n } from "react";
2
+ const s = (t, o = !0) => {
3
+ const [e, a] = l(() => {
4
4
  try {
5
- const r = localStorage.getItem(e);
5
+ const r = localStorage.getItem(t);
6
6
  if (!r)
7
7
  return null;
8
8
  if (o && !/^[a-zA-Z0-9_-]+$/.test(r))
9
9
  throw new Error("Invalid characters in stored value");
10
10
  return r;
11
11
  } catch {
12
- return localStorage.removeItem(e), null;
12
+ return localStorage.removeItem(t), null;
13
13
  }
14
14
  });
15
- return s(() => {
16
- t ? localStorage.setItem(e, t) : localStorage.removeItem(e);
17
- }, [t, e]), [t, a];
15
+ return n(() => {
16
+ try {
17
+ if (e) {
18
+ localStorage.setItem(t, e);
19
+ return;
20
+ }
21
+ } catch {
22
+ }
23
+ localStorage.removeItem(t);
24
+ }, [e, t]), [e, a];
18
25
  };
19
26
  export {
20
- c as default
27
+ s as default
21
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/box-ai-agent-selector",
3
- "version": "0.40.1",
3
+ "version": "0.40.3",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "peerDependencies": {
6
6
  "@ariakit/react": "^0.4.15",
@@ -13,10 +13,10 @@
13
13
  "devDependencies": {
14
14
  "@ariakit/react": "^0.4.15",
15
15
  "@box/babel-plugin-target-attributes": "1.3.0",
16
- "@box/blueprint-web": "^11.10.2",
17
- "@box/blueprint-web-assets": "^4.42.0",
16
+ "@box/blueprint-web": "^11.10.3",
17
+ "@box/blueprint-web-assets": "^4.43.0",
18
18
  "@box/eslint-plugin-blueprint": "^1.0.3",
19
- "@box/storybook-utils": "^0.12.1",
19
+ "@box/storybook-utils": "^0.12.2",
20
20
  "@testing-library/react": "^15.0.6",
21
21
  "react-intl": "^6.4.2"
22
22
  },