@kong-ui-public/error-boundary 0.0.2-pr.821.e7da777c.0 → 0.0.2-pr.821.f0cfb4ef.0

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/README.md CHANGED
@@ -23,7 +23,7 @@ The `ErrorBoundary` component will **always** capture any unhandled errors and p
23
23
 
24
24
  The `ErrorBoundary` component can be used to wrap a single component or an entire tree of children, tagging any errors that are captured in the DOM tree.
25
25
 
26
- When nesting `ErrorBoundary` components, the [`tags`](#tags) from any parent `ErrorBoundary` component will be passed down to its children and included in their `ErrorCallbackParams`.
26
+ When nesting `ErrorBoundary` components, the [`tags`](#tags) from any parent `ErrorBoundary` component will be passed down to its children and included in their `ErrorBoundaryCallbackParams`.
27
27
 
28
28
  ```html
29
29
  <template>
@@ -39,10 +39,10 @@ When nesting `ErrorBoundary` components, the [`tags`](#tags) from any parent `Er
39
39
  <ErrorBoundary :tags="['team-core-ui']">
40
40
  <CreditCardComponent />
41
41
  <!-- The fallback slot has access to all params -->
42
- <template #fallback="{ error, instance, componentName, info, tags }">
42
+ <template #fallback="{ error, context }">
43
43
  <div class="fallback-content">
44
44
  <p>This component has custom fallback UI; most likely just an icon, etc.</p>
45
- <p class="error-message">{{ componentName }}: {{ error.message }}</p>
45
+ <p class="error-message">{{ context.componentName }}: {{ error.message }}</p>
46
46
  </div>
47
47
  </template>
48
48
  </ErrorBoundary>
@@ -93,18 +93,14 @@ import ErrorBoundary from '@kong-ui-public/error-boundary' // No style imports n
93
93
  // Datadog package example
94
94
  import { datadogRum } from '@datadog/browser-rum'
95
95
 
96
-
97
96
  const app = createApp(App)
98
97
 
99
98
  app.use(ErrorBoundary, {
100
99
  // Provide a global, default `onError` callback for all ErrorBoundary instances
101
- onError: ({ error, instance, componentName, info, tags }) => {
100
+ onError({ error, context }) {
102
101
  // Example of sending errors to Datadog
103
102
  datadogRum.addError(error, {
104
- source: 'ErrorBoundary',
105
- component: componentName,
106
- tags,
107
- info,
103
+ ui: context,
108
104
  })
109
105
  },
110
106
  })
@@ -129,7 +125,7 @@ When registering the component locally, you can provide the `onError` callback a
129
125
  import { ErrorBoundary } from '@kong-ui-public/error-boundary' // No style imports needed
130
126
 
131
127
  const myTags = ['first-tag', 'another-tag']
132
- const customErrorCallback = ({ error, instance, componentName, info, tags }) => {
128
+ const customErrorCallback = ({ error, context }) => {
133
129
  // Do something fancy
134
130
  }
135
131
  </script>
@@ -145,12 +141,12 @@ The `default` slot should be utilized for your "potentially buggy" Vue component
145
141
 
146
142
  The `fallback` slot can optionally be used to provide a fallback UI should any child component (not already wrapped with another `ErrorBoundary` component) thrown an unhandled error. **The default fallback behavior is to render nothing in the UI.**
147
143
 
148
- The `fallback` slot has access to all of the `ErrorCallbackParams` as slot props:
144
+ The `fallback` slot has access to all of the `ErrorBoundaryCallbackParams` as slot props:
149
145
 
150
146
  ```html
151
147
  <ErrorBoundary :tags="myTags">
152
148
  <BuggyComponent />
153
- <template #fallback="{ error, instance, componentName, info, tags }">
149
+ <template #fallback="{ error, context }">
154
150
  <!-- Your fallback UI here -->
155
151
  </template>
156
152
  </ErrorBoundary>
@@ -170,10 +166,10 @@ For example, if you want to provide custom attributes to errors on Datadog, you
170
166
 
171
167
  #### `onError`
172
168
 
173
- - type: `Function as PropType<(payload: ErrorCallbackParams) => void>`
169
+ - type: `Function as PropType<(params: ErrorBoundaryCallbackParams) => void>`
174
170
  - required: `false`
175
171
  - default: `[]`
176
172
 
177
- A function to be called from the `ErrorBoundary` component when an error in a child component is captured. Receives a payload of [ErrorCallbackParams](src/types/error-boundary.ts).
173
+ A function to be called from the `ErrorBoundary` component when an error in a child component is captured. Receives params of [ErrorBoundaryCallbackParams](src/types/error-boundary.ts).
178
174
 
179
175
  > **Note**: Providing a callback function via the `onError` prop will take precedence over any callback function defined during global registration. You can also provide an empty function in order to prevent the global callback from being executed.
@@ -1,49 +1,63 @@
1
- import { defineComponent as y, inject as d, ref as i, computed as g, unref as m, provide as O, onErrorCaptured as R, renderSlot as f } from "vue";
2
- const E = "kong-ui-error-boundary-on-error", c = "kong-ui-error-boundary-tags", N = /* @__PURE__ */ y({
1
+ import { defineComponent as p, inject as c, ref as i, computed as y, unref as m, provide as v, onErrorCaptured as g, renderSlot as d } from "vue";
2
+ const E = "kong-ui-error-boundary-on-error", f = "kong-ui-error-boundary-tags", O = /* @__PURE__ */ p({
3
3
  __name: "ErrorBoundary",
4
4
  props: {
5
+ /**
6
+ * An optional array of strings to pass along to the context
7
+ */
5
8
  tags: {
6
9
  type: Array,
7
10
  required: !1,
8
- default: () => []
11
+ default: () => [],
12
+ // Ensure the value is an object, not a string
13
+ validator: (e) => typeof e == "object"
9
14
  },
15
+ /**
16
+ * An optional callback function to execute when an error is captured.
17
+ * This prop will take precedence over a plugin-provided onError callback.
18
+ */
10
19
  onError: {
11
20
  type: Function,
12
21
  required: !1,
13
22
  default: void 0
14
23
  }
15
24
  },
16
- setup(n) {
17
- const r = n, t = d(E, r.onError), _ = d(c, []), a = i(), u = g(() => {
25
+ setup(e) {
26
+ const r = e, u = c(E, r.onError), _ = c(f, []), n = i(), s = y(() => {
18
27
  const o = /* @__PURE__ */ new Set();
19
- for (const e of [...m(_), ...r.tags])
20
- o.add(e);
28
+ for (const t of [...m(_), ...r.tags])
29
+ o.add(t);
21
30
  return Array.from(o);
22
31
  });
23
- return O(c, u), R((o, e, p) => {
32
+ return v(f, s), g((o, t, a) => {
24
33
  var l;
25
- a.value = o;
26
- const s = {
27
- error: a.value,
28
- instance: e,
29
- info: p,
30
- tags: u.value,
31
- componentName: (l = e == null ? void 0 : e.$options) == null ? void 0 : l.__name
32
- };
33
- return typeof r.onError == "function" ? r.onError(s) : typeof t == "function" && t(s), !1;
34
- }), (o, e) => a.value ? f(o.$slots, "fallback", {
35
- key: 1,
36
- error: a.value,
37
- tags: n.tags
38
- }) : f(o.$slots, "default", { key: 0 });
34
+ return n.value = {
35
+ error: o,
36
+ context: {
37
+ componentName: ((l = t == null ? void 0 : t.$options) == null ? void 0 : l.__name) || "",
38
+ info: a,
39
+ // See here for codes returned in production: https://github.com/vuejs/core/blob/b8fc18c0b23be9a77b05dc41ed452a87a0becf82/packages/runtime-core/src/errorHandling.ts#L27
40
+ source: "ErrorBoundary",
41
+ // The name of this ErrorBoundary component
42
+ tags: s.value
43
+ }
44
+ }, typeof r.onError == "function" ? r.onError(n.value) : typeof u == "function" && u(n.value), !1;
45
+ }), (o, t) => {
46
+ var a;
47
+ return (a = n.value) != null && a.error ? d(o.$slots, "fallback", {
48
+ key: 1,
49
+ context: n.value.context,
50
+ error: n.value.error
51
+ }) : d(o.$slots, "default", { key: 0 });
52
+ };
39
53
  }
40
- }), k = {
54
+ }), N = {
41
55
  // Customize Vue plugin options as desired
42
- install: (n, r = {}) => {
43
- n.component(r.name || "ErrorBoundary", N), n.provide(E, r.onError);
56
+ install: (e, r = {}) => {
57
+ e.component(r.name || "ErrorBoundary", O), e.provide(E, r.onError);
44
58
  }
45
59
  };
46
60
  export {
47
- N as ErrorBoundary,
48
- k as default
61
+ O as ErrorBoundary,
62
+ N as default
49
63
  };
@@ -1 +1 @@
1
- (function(e,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(e=typeof globalThis<"u"?globalThis:e||self,r(e["kong-ui-public-error-boundary"]={},e.Vue))})(this,function(e,r){"use strict";const d="kong-ui-error-boundary-on-error",s="kong-ui-error-boundary-tags",f=r.defineComponent({__name:"ErrorBoundary",props:{tags:{type:Array,required:!1,default:()=>[]},onError:{type:Function,required:!1,default:void 0}},setup(a){const o=a,l=r.inject(d,o.onError),E=r.inject(s,[]),u=r.ref(),i=r.computed(()=>{const n=new Set;for(const t of[...r.unref(E),...o.tags])n.add(t);return Array.from(n)});return r.provide(s,i),r.onErrorCaptured((n,t,_)=>{var p;u.value=n;const c={error:u.value,instance:t,info:_,tags:i.value,componentName:(p=t==null?void 0:t.$options)==null?void 0:p.__name};return typeof o.onError=="function"?o.onError(c):typeof l=="function"&&l(c),!1}),(n,t)=>u.value?r.renderSlot(n.$slots,"fallback",{key:1,error:u.value,tags:a.tags}):r.renderSlot(n.$slots,"default",{key:0})}}),y={install:(a,o={})=>{a.component(o.name||"ErrorBoundary",f),a.provide(d,o.onError)}};e.ErrorBoundary=f,e.default=y,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(e,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(e=typeof globalThis<"u"?globalThis:e||self,r(e["kong-ui-public-error-boundary"]={},e.Vue))})(this,function(e,r){"use strict";const s="kong-ui-error-boundary-on-error",l="kong-ui-error-boundary-tags",f=r.defineComponent({__name:"ErrorBoundary",props:{tags:{type:Array,required:!1,default:()=>[],validator:t=>typeof t=="object"},onError:{type:Function,required:!1,default:void 0}},setup(t){const o=t,i=r.inject(s,o.onError),y=r.inject(l,[]),u=r.ref(),c=r.computed(()=>{const n=new Set;for(const a of[...r.unref(y),...o.tags])n.add(a);return Array.from(n)});return r.provide(l,c),r.onErrorCaptured((n,a,d)=>{var p;return u.value={error:n,context:{componentName:((p=a==null?void 0:a.$options)==null?void 0:p.__name)||"",info:d,source:"ErrorBoundary",tags:c.value}},typeof o.onError=="function"?o.onError(u.value):typeof i=="function"&&i(u.value),!1}),(n,a)=>{var d;return(d=u.value)!=null&&d.error?r.renderSlot(n.$slots,"fallback",{key:1,context:u.value.context,error:u.value.error}):r.renderSlot(n.$slots,"default",{key:0})}}}),_={install:(t,o={})=>{t.component(o.name||"ErrorBoundary",f),t.provide(s,o.onError)}};e.ErrorBoundary=f,e.default=_,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,35 +1,51 @@
1
1
  import type { PropType } from 'vue';
2
- import type { ErrorCallbackParams } from '../types';
2
+ import type { ErrorBoundaryCallbackParams } from '../types';
3
3
  declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
4
+ /**
5
+ * An optional array of strings to pass along to the context
6
+ */
4
7
  tags: {
5
8
  type: PropType<string[]>;
6
9
  required: false;
7
10
  default: () => never[];
11
+ validator: (value: any) => boolean;
8
12
  };
13
+ /**
14
+ * An optional callback function to execute when an error is captured.
15
+ * This prop will take precedence over a plugin-provided onError callback.
16
+ */
9
17
  onError: {
10
- type: PropType<(payload: ErrorCallbackParams) => void>;
18
+ type: PropType<(params: ErrorBoundaryCallbackParams) => void>;
11
19
  required: false;
12
20
  default: undefined;
13
21
  };
14
22
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
23
+ /**
24
+ * An optional array of strings to pass along to the context
25
+ */
15
26
  tags: {
16
27
  type: PropType<string[]>;
17
28
  required: false;
18
29
  default: () => never[];
30
+ validator: (value: any) => boolean;
19
31
  };
32
+ /**
33
+ * An optional callback function to execute when an error is captured.
34
+ * This prop will take precedence over a plugin-provided onError callback.
35
+ */
20
36
  onError: {
21
- type: PropType<(payload: ErrorCallbackParams) => void>;
37
+ type: PropType<(params: ErrorBoundaryCallbackParams) => void>;
22
38
  required: false;
23
39
  default: undefined;
24
40
  };
25
41
  }>>, {
26
42
  tags: string[];
27
- onError: (payload: ErrorCallbackParams) => void;
43
+ onError: (params: ErrorBoundaryCallbackParams) => void;
28
44
  }, {}>, {
29
45
  default?(_: {}): any;
30
46
  fallback?(_: {
31
- error: any;
32
- tags: string[];
47
+ context: import("../types").ErrorBoundaryContext;
48
+ error: {};
33
49
  }): any;
34
50
  }>;
35
51
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundary.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.vue.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,QAAQ,EAAE,MAAM,KAAK,CAAA;AAE5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4JnD,wBAA8G;AAE9G,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,QAAO;QAClD,MAAM,EAAE,CAAC,CAAC;KACT,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"ErrorBoundary.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.vue.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,QAAQ,EAAE,MAAM,KAAK,CAAA;AAK5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAA;;IAkKzD;;OAEG;;;;;;;IAQH;;;OAGG;;;;;;;IAbH;;OAEG;;;;;;;IAQH;;;OAGG;;;;;;;;;;;;;;;;AAaL,wBAAwG;AAGxG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,QAAO;QAClD,MAAM,EAAE,CAAC,CAAC;KACT,CAAA;CAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,eAAO,MAAM,6CAA6C,oCAAoC,CAAA;AAC9F,oGAAoG;AACpG,eAAO,MAAM,yCAAyC,gCAAgC,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,eAAO,MAAM,6CAA6C,oCAAoC,CAAA;AAE9F,oGAAoG;AACpG,eAAO,MAAM,yCAAyC,gCAAgC,CAAA"}
@@ -1,13 +1,15 @@
1
- import type { ComponentPublicInstance } from 'vue';
2
- export interface ErrorCallbackParams {
3
- error: unknown;
4
- instance: ComponentPublicInstance | null;
5
- componentName?: string;
1
+ export interface ErrorBoundaryContext {
2
+ componentName: string;
6
3
  info: string;
4
+ source: string;
7
5
  tags: string[];
8
6
  }
7
+ export interface ErrorBoundaryCallbackParams {
8
+ error: unknown;
9
+ context: ErrorBoundaryContext;
10
+ }
9
11
  export interface ErrorBoundaryPluginOptions {
10
12
  name?: string;
11
- onError?: ({ error, instance, componentName, info, tags }: ErrorCallbackParams) => void;
13
+ onError?: ({ error, context: { componentName, info, source, tags } }: ErrorBoundaryCallbackParams) => void;
12
14
  }
13
15
  //# sourceMappingURL=error-boundary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/types/error-boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,KAAK,CAAA;AAElD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,uBAAuB,GAAG,IAAI,CAAA;IACxC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,mBAAmB,KAAK,IAAI,CAAA;CACxF"}
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/types/error-boundary.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,oBAAoB,CAAA;CAC9B;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,2BAA2B,KAAK,IAAI,CAAA;CAC3G"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong-ui-public/error-boundary",
3
- "version": "0.0.2-pr.821.e7da777c.0",
3
+ "version": "0.0.2-pr.821.f0cfb4ef.0",
4
4
  "type": "module",
5
5
  "main": "./dist/error-boundary.umd.js",
6
6
  "module": "./dist/error-boundary.es.js",