@ohbug/react 1.0.14 → 2.0.1

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
@@ -2,14 +2,13 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@ohbug/react.svg?style=flat-square)](https://www.npmjs.com/package/@ohbug/react)
4
4
  [![npm bundle size](https://img.shields.io/bundlephobia/min/@ohbug/react?style=flat-square)](https://bundlephobia.com/result?p=@ohbug/react)
5
- [![Code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6
5
 
7
6
  English | [简体中文](./README-zh_CN.md)
8
7
 
9
8
  ## Installation
10
9
 
11
10
  ```
12
- yarn add @ohbug/browser @ohbug/react
11
+ pnpm instal @ohbug/browser @ohbug/react
13
12
  ```
14
13
 
15
14
  ## Usage
@@ -17,15 +16,14 @@ yarn add @ohbug/browser @ohbug/react
17
16
  ```jsx
18
17
  import React from 'react'
19
18
  import Ohbug from '@ohbug/browser'
20
- import OhbugReact from '@ohbug/react'
19
+ import { OhbugErrorBoundary } from '@ohbug/react'
21
20
 
22
- const client = Ohbug.init({ apiKey: 'YOUR_API_KEY' })
23
- const OhbugErrorBoundary = client.use(OhbugReact, React)
21
+ const client = Ohbug.setup({ apiKey: 'YOUR_API_KEY' })
24
22
 
25
23
  function App() {
26
24
  return (
27
25
  <div className="App">
28
- <OhbugErrorBoundary>
26
+ <OhbugErrorBoundary client={client}>
29
27
  <HelloWorld />
30
28
  </OhbugErrorBoundary>
31
29
  </div>
package/dist/index.d.ts CHANGED
@@ -1,3 +1,23 @@
1
- export type { ReactErrorDetail } from './OhbugErrorBoundary';
2
- export { extension as default } from './extension';
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { OhbugBaseDetail, OhbugClient } from '@ohbug/types';
2
+ import React from 'react';
3
+
4
+ interface ReactErrorDetail extends OhbugBaseDetail {
5
+ name: string;
6
+ stack?: string;
7
+ errorInfo: any;
8
+ }
9
+ interface ErrorBoundaryProp {
10
+ client: OhbugClient;
11
+ FallbackComponent?: React.ReactElement;
12
+ children?: React.ReactNode;
13
+ }
14
+ interface ErrorBoundaryState {
15
+ error: any;
16
+ }
17
+ declare class OhbugErrorBoundary extends React.Component<ErrorBoundaryProp, ErrorBoundaryState> {
18
+ constructor(props: ErrorBoundaryProp);
19
+ componentDidCatch(error: Error, info: any): void;
20
+ render(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined;
21
+ }
22
+
23
+ export { OhbugErrorBoundary, ReactErrorDetail };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var m=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of y(e))!f.call(t,n)&&n!==r&&a(t,n,{get:()=>e[n],enumerable:!(o=u(e,n))||o.enumerable});return t};var E=(t,e,r)=>(r=t!=null?m(d(t)):{},c(e||!t||!t.__esModule?a(r,"default",{value:t,enumerable:!0}):r,t)),g=t=>c(a({},"__esModule",{value:!0}),t);var C={};h(C,{OhbugErrorBoundary:()=>s});module.exports=g(C);var i=E(require("react")),l=require("@ohbug/core"),s=class extends i.default.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e,r){let{client:o}=this.props,n={name:e.name,message:e.message,stack:e.stack,errorInfo:r},p=o.createEvent({category:"error",type:l.EventTypes.REACT,detail:n});o.notify(p),this.setState({error:e})}render(){let{error:e}=this.state,{FallbackComponent:r,children:o}=this.props;return e?r||null:o}};0&&(module.exports={OhbugErrorBoundary});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import i from"react";import{EventTypes as l}from"@ohbug/core";var o=class extends i.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e,t){let{client:r}=this.props,n={name:e.name,message:e.message,stack:e.stack,errorInfo:t},a=r.createEvent({category:"error",type:l.REACT,detail:n});r.notify(a),this.setState({error:e})}render(){let{error:e}=this.state,{FallbackComponent:t,children:r}=this.props;return e?t||null:r}};export{o as OhbugErrorBoundary};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@ohbug/react",
3
- "version": "1.0.14",
3
+ "version": "2.0.1",
4
4
  "description": "Ohbug SDK for React",
5
+ "license": "Apache-2.0",
5
6
  "author": "chenyueban <jasonchan0527@gmail.com>",
6
7
  "homepage": "https://github.com/ohbug-org/ohbug",
7
8
  "bugs": {
@@ -11,40 +12,36 @@
11
12
  "type": "git",
12
13
  "url": "https://github.com/ohbug-org/ohbug"
13
14
  },
14
- "license": "Apache-2.0",
15
- "main": "./dist/ohbug-react.umd.js",
16
- "module": "./dist/ohbug-react.es.js",
17
- "unpkg": "./dist/ohbug-react.umd.js",
18
- "jsdelivr": "./dist/ohbug-react.umd.js",
19
- "types": "./dist/index.d.ts",
15
+ "main": "dist/index.js",
16
+ "module": "dist/index.mjs",
17
+ "types": "dist/index.d.ts",
20
18
  "exports": {
21
19
  ".": {
22
- "import": "./dist/ohbug-react.es.js",
23
- "require": "./dist/ohbug-react.umd.js"
20
+ "require": "./dist/index.js",
21
+ "import": "./dist/index.mjs",
22
+ "types": "./dist/index.d.ts"
24
23
  }
25
24
  },
26
25
  "files": [
27
26
  "dist"
28
27
  ],
29
- "dependencies": {
30
- "@ohbug/core": "^1.1.6"
31
- },
32
- "devDependencies": {
33
- "@types/react": "^17.0.20"
34
- },
28
+ "sideEffects": false,
35
29
  "peerDependencies": {
36
30
  "react": "^16.8.6"
37
31
  },
38
- "buildOptions": {
39
- "name": "OhbugReact",
40
- "formats": [
41
- "es",
42
- "umd"
43
- ],
44
- "order": 4
32
+ "dependencies": {
33
+ "@ohbug/core": "2.0.1",
34
+ "@ohbug/types": "2.0.1"
35
+ },
36
+ "devDependencies": {
37
+ "@ohbug/browser": "2.0.1",
38
+ "@types/react": "^18.0.9"
45
39
  },
46
40
  "publishConfig": {
47
41
  "access": "public"
48
42
  },
49
- "gitHead": "10a43cc9dc7cceec6a209746b0258de14390aa32"
50
- }
43
+ "scripts": {
44
+ "build": "tsup",
45
+ "dev": "tsup --watch"
46
+ }
47
+ }
@@ -1,44 +0,0 @@
1
- import type { OhbugBaseDetail, OhbugClient } from '@ohbug/types';
2
- import React from 'react';
3
- export interface ReactErrorDetail extends OhbugBaseDetail {
4
- name: string;
5
- stack?: string;
6
- errorInfo: any;
7
- }
8
- interface ErrorBoundaryProp {
9
- FallbackComponent: React.ReactElement;
10
- }
11
- interface ErrorBoundaryState {
12
- error: any;
13
- info: any;
14
- }
15
- export declare function createOhbugErrorBoundary(client: OhbugClient, react: typeof React): {
16
- new (props: ErrorBoundaryProp): {
17
- componentDidCatch(error: Error, info: any): void;
18
- render(): React.ReactNode;
19
- context: any;
20
- setState<K extends keyof ErrorBoundaryState>(state: ErrorBoundaryState | ((prevState: Readonly<ErrorBoundaryState>, props: Readonly<ErrorBoundaryProp>) => ErrorBoundaryState | Pick<ErrorBoundaryState, K> | null) | Pick<ErrorBoundaryState, K> | null, callback?: (() => void) | undefined): void;
21
- forceUpdate(callback?: (() => void) | undefined): void;
22
- readonly props: Readonly<ErrorBoundaryProp> & Readonly<{
23
- children?: React.ReactNode;
24
- }>;
25
- state: Readonly<ErrorBoundaryState>;
26
- refs: {
27
- [key: string]: React.ReactInstance;
28
- };
29
- componentDidMount?(): void;
30
- shouldComponentUpdate?(nextProps: Readonly<ErrorBoundaryProp>, nextState: Readonly<ErrorBoundaryState>, nextContext: any): boolean;
31
- componentWillUnmount?(): void;
32
- getSnapshotBeforeUpdate?(prevProps: Readonly<ErrorBoundaryProp>, prevState: Readonly<ErrorBoundaryState>): any;
33
- componentDidUpdate?(prevProps: Readonly<ErrorBoundaryProp>, prevState: Readonly<ErrorBoundaryState>, snapshot?: any): void;
34
- componentWillMount?(): void;
35
- UNSAFE_componentWillMount?(): void;
36
- componentWillReceiveProps?(nextProps: Readonly<ErrorBoundaryProp>, nextContext: any): void;
37
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<ErrorBoundaryProp>, nextContext: any): void;
38
- componentWillUpdate?(nextProps: Readonly<ErrorBoundaryProp>, nextState: Readonly<ErrorBoundaryState>, nextContext: any): void;
39
- UNSAFE_componentWillUpdate?(nextProps: Readonly<ErrorBoundaryProp>, nextState: Readonly<ErrorBoundaryState>, nextContext: any): void;
40
- };
41
- contextType?: React.Context<any> | undefined;
42
- };
43
- export {};
44
- //# sourceMappingURL=OhbugErrorBoundary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OhbugErrorBoundary.d.ts","sourceRoot":"","sources":["../src/OhbugErrorBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,GAAG,CAAA;CACf;AAED,UAAU,iBAAiB;IACzB,iBAAiB,EAAE,KAAK,CAAC,YAAY,CAAA;CACtC;AACD,UAAU,kBAAkB;IAC1B,KAAK,EAAE,GAAG,CAAA;IACV,IAAI,EAAE,GAAG,CAAA;CACV;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,OAAO,KAAK;gBAME,iBAAiB;iCAQX,KAAK,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;EA8B5C"}
@@ -1,2 +0,0 @@
1
- export declare const extension: import("@ohbug/types").OhbugExtension<any>;
2
- //# sourceMappingURL=extension.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS,4CAQpB,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,aAAa,CAAA"}
@@ -1,270 +0,0 @@
1
- /*! *****************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
-
16
- var __assign = function() {
17
- __assign = Object.assign || function __assign(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
- }
22
- return t;
23
- };
24
- return __assign.apply(this, arguments);
25
- };
26
-
27
- function isString(value) {
28
- return typeof value === 'string';
29
- }
30
- function isObject(value) {
31
- return Object.prototype.toString.call(value) === '[object Object]';
32
- }
33
-
34
- function createExtension(extension) {
35
- return extension;
36
- }
37
-
38
- var Action = /** @class */ (function () {
39
- function Action(message, data, type, timestamp) {
40
- this.type = type;
41
- this.timestamp = timestamp || new Date().toISOString();
42
- this.message = message;
43
- this.data = data;
44
- }
45
- return Action;
46
- }());
47
- function getErrorMessage(message, data) {
48
- return new Error("Invalid data\n- " + message + ", got " + JSON.stringify(data));
49
- }
50
-
51
- function addMetaData(map, section, data) {
52
- if (!section)
53
- return;
54
- map[section] = data;
55
- }
56
- function getMetaData(map, section) {
57
- if (map[section]) {
58
- return map[section];
59
- }
60
- return undefined;
61
- }
62
- function deleteMetaData(map, section) {
63
- if (map[section]) {
64
- return delete map[section];
65
- }
66
- return undefined;
67
- }
68
-
69
- /** @class */ ((function () {
70
- function Event(values, client) {
71
- var apiKey = values.apiKey, appVersion = values.appVersion, appType = values.appType, releaseStage = values.releaseStage, timestamp = values.timestamp, category = values.category, type = values.type, sdk = values.sdk, detail = values.detail, device = values.device, user = values.user, actions = values.actions, metaData = values.metaData;
72
- this.apiKey = apiKey;
73
- this.appVersion = appVersion;
74
- this.appType = appType;
75
- this.releaseStage = releaseStage;
76
- this.timestamp = timestamp;
77
- this.category = category;
78
- this.type = type;
79
- this.sdk = sdk;
80
- this.detail = detail;
81
- this.device = device;
82
- this.user = user;
83
- this.actions = actions;
84
- this.metaData = metaData;
85
- this._client = client;
86
- }
87
- Object.defineProperty(Event.prototype, "_isOhbugEvent", {
88
- get: function () {
89
- return true;
90
- },
91
- enumerable: false,
92
- configurable: true
93
- });
94
- /**
95
- * Add an action.
96
- * Once the threshold is reached, the oldest breadcrumbs will be deleted.
97
- * 新增一个动作。
98
- * 一旦达到阈值,最老的 Action 将被删除。
99
- *
100
- * @param message
101
- * @param data
102
- * @param type
103
- * @param timestamp
104
- */
105
- Event.prototype.addAction = function (message, data, type, timestamp) {
106
- var _a, _b;
107
- var actions = this.actions;
108
- var targetMessage = isString(message) ? message : '';
109
- var targetData = data || {};
110
- var targetType = isString(type) ? type : '';
111
- var action = new Action(targetMessage, targetData, targetType, timestamp);
112
- if (actions.length >= ((_b = (_a = this._client) === null || _a === void 0 ? void 0 : _a._config.maxActions) !== null && _b !== void 0 ? _b : 30)) {
113
- actions.shift();
114
- }
115
- actions.push(action);
116
- };
117
- /**
118
- * Get current user information
119
- * 获取当前的用户信息
120
- */
121
- Event.prototype.getUser = function () {
122
- return this.user;
123
- };
124
- /**
125
- * Set current user information
126
- * 设置当前的用户信息
127
- */
128
- Event.prototype.setUser = function (user) {
129
- var _a;
130
- if (isObject(user) && Object.keys(user).length <= 6) {
131
- this.user = __assign(__assign({}, this.user), user);
132
- return this.getUser();
133
- }
134
- (_a = this._client) === null || _a === void 0 ? void 0 : _a._logger.warn(getErrorMessage('setUser should be an object and have up to 6 attributes', user));
135
- return undefined;
136
- };
137
- /**
138
- * Add metaData
139
- * 新增 metaData
140
- *
141
- * @param section
142
- * @param data
143
- */
144
- Event.prototype.addMetaData = function (section, data) {
145
- return addMetaData(this.metaData, section, data);
146
- };
147
- /**
148
- * Get metaData
149
- * 获取 metaData
150
- *
151
- * @param section
152
- */
153
- Event.prototype.getMetaData = function (section) {
154
- return getMetaData(this.metaData, section);
155
- };
156
- /**
157
- * Delete metaData
158
- * 删除 metaData
159
- *
160
- * @param section
161
- */
162
- Event.prototype.deleteMetaData = function (section) {
163
- return deleteMetaData(this.metaData, section);
164
- };
165
- Event.prototype.toJSON = function () {
166
- var _a = this, apiKey = _a.apiKey, appVersion = _a.appVersion, appType = _a.appType, timestamp = _a.timestamp, category = _a.category, type = _a.type, sdk = _a.sdk, device = _a.device, detail = _a.detail, user = _a.user, actions = _a.actions, metaData = _a.metaData, releaseStage = _a.releaseStage;
167
- return {
168
- apiKey: apiKey,
169
- appVersion: appVersion,
170
- appType: appType,
171
- timestamp: timestamp,
172
- category: category,
173
- type: type,
174
- sdk: sdk,
175
- device: device,
176
- detail: detail,
177
- user: user,
178
- actions: actions,
179
- metaData: metaData,
180
- releaseStage: releaseStage,
181
- };
182
- };
183
- return Event;
184
- })());
185
-
186
- /*! *****************************************************************************
187
- Copyright (c) Microsoft Corporation.
188
-
189
- Permission to use, copy, modify, and/or distribute this software for any
190
- purpose with or without fee is hereby granted.
191
-
192
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
193
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
194
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
195
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
196
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
197
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
198
- PERFORMANCE OF THIS SOFTWARE.
199
- ***************************************************************************** */
200
- /* global Reflect, Promise */
201
-
202
- var extendStatics = function(d, b) {
203
- extendStatics = Object.setPrototypeOf ||
204
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
205
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
206
- return extendStatics(d, b);
207
- };
208
-
209
- function __extends(d, b) {
210
- if (typeof b !== "function" && b !== null)
211
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
212
- extendStatics(d, b);
213
- function __() { this.constructor = d; }
214
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
215
- }
216
-
217
- function createOhbugErrorBoundary(client, react) {
218
- return /** @class */ (function (_super) {
219
- __extends(OhbugErrorBoundary, _super);
220
- function OhbugErrorBoundary(props) {
221
- var _this = _super.call(this, props) || this;
222
- _this.state = {
223
- error: null,
224
- info: null,
225
- };
226
- return _this;
227
- }
228
- OhbugErrorBoundary.prototype.componentDidCatch = function (error, info) {
229
- var detail = {
230
- name: error.name,
231
- message: error.message,
232
- stack: error.stack,
233
- errorInfo: info,
234
- };
235
- var event = client.createEvent({
236
- category: 'error',
237
- type: 'react',
238
- detail: detail,
239
- });
240
- client.notify(event);
241
- this.setState({
242
- error: error,
243
- info: info,
244
- });
245
- };
246
- OhbugErrorBoundary.prototype.render = function () {
247
- var error = this.state.error;
248
- if (error) {
249
- var FallbackComponent = this.props.FallbackComponent;
250
- if (FallbackComponent)
251
- return FallbackComponent;
252
- return null;
253
- }
254
- return this.props.children;
255
- };
256
- return OhbugErrorBoundary;
257
- }(react.Component));
258
- }
259
-
260
- var extension = createExtension({
261
- name: 'OhbugReact',
262
- init: function (client, react) {
263
- if (!react) {
264
- throw new Error('Ohbug @ohbug/react reference to `React` was undefined');
265
- }
266
- return createOhbugErrorBoundary(client, react);
267
- },
268
- });
269
-
270
- export { extension as default };
@@ -1,30 +0,0 @@
1
- /*! *****************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- var t=function(){return(t=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function e(t){return"string"==typeof t}var r=function(t,e,r,n){this.type=r,this.timestamp=n||(new Date).toISOString(),this.message=t,this.data=e};!function(){function n(t,e){var r=t.apiKey,n=t.appVersion,o=t.appType,a=t.releaseStage,i=t.timestamp,s=t.category,p=t.type,c=t.sdk,u=t.detail,l=t.device,f=t.user,h=t.actions,y=t.metaData;this.apiKey=r,this.appVersion=n,this.appType=o,this.releaseStage=a,this.timestamp=i,this.category=s,this.type=p,this.sdk=c,this.detail=u,this.device=l,this.user=f,this.actions=h,this.metaData=y,this._client=e}Object.defineProperty(n.prototype,"_isOhbugEvent",{get:function(){return!0},enumerable:!1,configurable:!0}),n.prototype.addAction=function(t,n,o,a){var i,s,p=this.actions,c=e(t)?t:"",u=n||{},l=e(o)?o:"",f=new r(c,u,l,a);p.length>=(null!==(s=null===(i=this._client)||void 0===i?void 0:i._config.maxActions)&&void 0!==s?s:30)&&p.shift(),p.push(f)},n.prototype.getUser=function(){return this.user},n.prototype.setUser=function(e){var r,n,o;if(n=e,"[object Object]"===Object.prototype.toString.call(n)&&Object.keys(e).length<=6)return this.user=t(t({},this.user),e),this.getUser();null===(r=this._client)||void 0===r||r._logger.warn((o=e,new Error("Invalid data\n- "+"setUser should be an object and have up to 6 attributes"+", got "+JSON.stringify(o))))},n.prototype.addMetaData=function(t,e){return function(t,e,r){e&&(t[e]=r)}(this.metaData,t,e)},n.prototype.getMetaData=function(t){return function(t,e){if(t[e])return t[e]}(this.metaData,t)},n.prototype.deleteMetaData=function(t){return function(t,e){if(t[e])return delete t[e]}(this.metaData,t)},n.prototype.toJSON=function(){var t=this;return{apiKey:t.apiKey,appVersion:t.appVersion,appType:t.appType,timestamp:t.timestamp,category:t.category,type:t.type,sdk:t.sdk,device:t.device,detail:t.detail,user:t.user,actions:t.actions,metaData:t.metaData,releaseStage:t.releaseStage}}}();
16
- /*! *****************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */
30
- var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};function o(t,e){return function(e){function r(t){var r=e.call(this,t)||this;return r.state={error:null,info:null},r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(r,e),r.prototype.componentDidCatch=function(e,r){var n={name:e.name,message:e.message,stack:e.stack,errorInfo:r},o=t.createEvent({category:"error",type:"react",detail:n});t.notify(o),this.setState({error:e,info:r})},r.prototype.render=function(){if(this.state.error){var t=this.props.FallbackComponent;return t||null}return this.props.children},r}(e.Component)}var a={name:"OhbugReact",init:function(t,e){if(!e)throw new Error("Ohbug @ohbug/react reference to `React` was undefined");return o(t,e)}};export{a as default};
@@ -1,278 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.OhbugReact = factory());
5
- }(this, (function () { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
-
22
- var __assign = function() {
23
- __assign = Object.assign || function __assign(t) {
24
- for (var s, i = 1, n = arguments.length; i < n; i++) {
25
- s = arguments[i];
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
27
- }
28
- return t;
29
- };
30
- return __assign.apply(this, arguments);
31
- };
32
-
33
- function isString(value) {
34
- return typeof value === 'string';
35
- }
36
- function isObject(value) {
37
- return Object.prototype.toString.call(value) === '[object Object]';
38
- }
39
-
40
- function createExtension(extension) {
41
- return extension;
42
- }
43
-
44
- var Action = /** @class */ (function () {
45
- function Action(message, data, type, timestamp) {
46
- this.type = type;
47
- this.timestamp = timestamp || new Date().toISOString();
48
- this.message = message;
49
- this.data = data;
50
- }
51
- return Action;
52
- }());
53
- function getErrorMessage(message, data) {
54
- return new Error("Invalid data\n- " + message + ", got " + JSON.stringify(data));
55
- }
56
-
57
- function addMetaData(map, section, data) {
58
- if (!section)
59
- return;
60
- map[section] = data;
61
- }
62
- function getMetaData(map, section) {
63
- if (map[section]) {
64
- return map[section];
65
- }
66
- return undefined;
67
- }
68
- function deleteMetaData(map, section) {
69
- if (map[section]) {
70
- return delete map[section];
71
- }
72
- return undefined;
73
- }
74
-
75
- /** @class */ ((function () {
76
- function Event(values, client) {
77
- var apiKey = values.apiKey, appVersion = values.appVersion, appType = values.appType, releaseStage = values.releaseStage, timestamp = values.timestamp, category = values.category, type = values.type, sdk = values.sdk, detail = values.detail, device = values.device, user = values.user, actions = values.actions, metaData = values.metaData;
78
- this.apiKey = apiKey;
79
- this.appVersion = appVersion;
80
- this.appType = appType;
81
- this.releaseStage = releaseStage;
82
- this.timestamp = timestamp;
83
- this.category = category;
84
- this.type = type;
85
- this.sdk = sdk;
86
- this.detail = detail;
87
- this.device = device;
88
- this.user = user;
89
- this.actions = actions;
90
- this.metaData = metaData;
91
- this._client = client;
92
- }
93
- Object.defineProperty(Event.prototype, "_isOhbugEvent", {
94
- get: function () {
95
- return true;
96
- },
97
- enumerable: false,
98
- configurable: true
99
- });
100
- /**
101
- * Add an action.
102
- * Once the threshold is reached, the oldest breadcrumbs will be deleted.
103
- * 新增一个动作。
104
- * 一旦达到阈值,最老的 Action 将被删除。
105
- *
106
- * @param message
107
- * @param data
108
- * @param type
109
- * @param timestamp
110
- */
111
- Event.prototype.addAction = function (message, data, type, timestamp) {
112
- var _a, _b;
113
- var actions = this.actions;
114
- var targetMessage = isString(message) ? message : '';
115
- var targetData = data || {};
116
- var targetType = isString(type) ? type : '';
117
- var action = new Action(targetMessage, targetData, targetType, timestamp);
118
- if (actions.length >= ((_b = (_a = this._client) === null || _a === void 0 ? void 0 : _a._config.maxActions) !== null && _b !== void 0 ? _b : 30)) {
119
- actions.shift();
120
- }
121
- actions.push(action);
122
- };
123
- /**
124
- * Get current user information
125
- * 获取当前的用户信息
126
- */
127
- Event.prototype.getUser = function () {
128
- return this.user;
129
- };
130
- /**
131
- * Set current user information
132
- * 设置当前的用户信息
133
- */
134
- Event.prototype.setUser = function (user) {
135
- var _a;
136
- if (isObject(user) && Object.keys(user).length <= 6) {
137
- this.user = __assign(__assign({}, this.user), user);
138
- return this.getUser();
139
- }
140
- (_a = this._client) === null || _a === void 0 ? void 0 : _a._logger.warn(getErrorMessage('setUser should be an object and have up to 6 attributes', user));
141
- return undefined;
142
- };
143
- /**
144
- * Add metaData
145
- * 新增 metaData
146
- *
147
- * @param section
148
- * @param data
149
- */
150
- Event.prototype.addMetaData = function (section, data) {
151
- return addMetaData(this.metaData, section, data);
152
- };
153
- /**
154
- * Get metaData
155
- * 获取 metaData
156
- *
157
- * @param section
158
- */
159
- Event.prototype.getMetaData = function (section) {
160
- return getMetaData(this.metaData, section);
161
- };
162
- /**
163
- * Delete metaData
164
- * 删除 metaData
165
- *
166
- * @param section
167
- */
168
- Event.prototype.deleteMetaData = function (section) {
169
- return deleteMetaData(this.metaData, section);
170
- };
171
- Event.prototype.toJSON = function () {
172
- var _a = this, apiKey = _a.apiKey, appVersion = _a.appVersion, appType = _a.appType, timestamp = _a.timestamp, category = _a.category, type = _a.type, sdk = _a.sdk, device = _a.device, detail = _a.detail, user = _a.user, actions = _a.actions, metaData = _a.metaData, releaseStage = _a.releaseStage;
173
- return {
174
- apiKey: apiKey,
175
- appVersion: appVersion,
176
- appType: appType,
177
- timestamp: timestamp,
178
- category: category,
179
- type: type,
180
- sdk: sdk,
181
- device: device,
182
- detail: detail,
183
- user: user,
184
- actions: actions,
185
- metaData: metaData,
186
- releaseStage: releaseStage,
187
- };
188
- };
189
- return Event;
190
- })());
191
-
192
- /*! *****************************************************************************
193
- Copyright (c) Microsoft Corporation.
194
-
195
- Permission to use, copy, modify, and/or distribute this software for any
196
- purpose with or without fee is hereby granted.
197
-
198
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
199
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
200
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
201
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
202
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
203
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
204
- PERFORMANCE OF THIS SOFTWARE.
205
- ***************************************************************************** */
206
- /* global Reflect, Promise */
207
-
208
- var extendStatics = function(d, b) {
209
- extendStatics = Object.setPrototypeOf ||
210
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
211
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
212
- return extendStatics(d, b);
213
- };
214
-
215
- function __extends(d, b) {
216
- if (typeof b !== "function" && b !== null)
217
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
218
- extendStatics(d, b);
219
- function __() { this.constructor = d; }
220
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
221
- }
222
-
223
- function createOhbugErrorBoundary(client, react) {
224
- return /** @class */ (function (_super) {
225
- __extends(OhbugErrorBoundary, _super);
226
- function OhbugErrorBoundary(props) {
227
- var _this = _super.call(this, props) || this;
228
- _this.state = {
229
- error: null,
230
- info: null,
231
- };
232
- return _this;
233
- }
234
- OhbugErrorBoundary.prototype.componentDidCatch = function (error, info) {
235
- var detail = {
236
- name: error.name,
237
- message: error.message,
238
- stack: error.stack,
239
- errorInfo: info,
240
- };
241
- var event = client.createEvent({
242
- category: 'error',
243
- type: 'react',
244
- detail: detail,
245
- });
246
- client.notify(event);
247
- this.setState({
248
- error: error,
249
- info: info,
250
- });
251
- };
252
- OhbugErrorBoundary.prototype.render = function () {
253
- var error = this.state.error;
254
- if (error) {
255
- var FallbackComponent = this.props.FallbackComponent;
256
- if (FallbackComponent)
257
- return FallbackComponent;
258
- return null;
259
- }
260
- return this.props.children;
261
- };
262
- return OhbugErrorBoundary;
263
- }(react.Component));
264
- }
265
-
266
- var extension = createExtension({
267
- name: 'OhbugReact',
268
- init: function (client, react) {
269
- if (!react) {
270
- throw new Error('Ohbug @ohbug/react reference to `React` was undefined');
271
- }
272
- return createOhbugErrorBoundary(client, react);
273
- },
274
- });
275
-
276
- return extension;
277
-
278
- })));
@@ -1,30 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).OhbugReact=e()}(this,(function(){"use strict";
2
- /*! *****************************************************************************
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
- PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */var t=function(){return(t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function e(t){return"string"==typeof t}var n=function(t,e,n,r){this.type=n,this.timestamp=r||(new Date).toISOString(),this.message=t,this.data=e};!function(){function r(t,e){var n=t.apiKey,r=t.appVersion,o=t.appType,i=t.releaseStage,a=t.timestamp,s=t.category,p=t.type,c=t.sdk,u=t.detail,f=t.device,l=t.user,h=t.actions,y=t.metaData;this.apiKey=n,this.appVersion=r,this.appType=o,this.releaseStage=i,this.timestamp=a,this.category=s,this.type=p,this.sdk=c,this.detail=u,this.device=f,this.user=l,this.actions=h,this.metaData=y,this._client=e}Object.defineProperty(r.prototype,"_isOhbugEvent",{get:function(){return!0},enumerable:!1,configurable:!0}),r.prototype.addAction=function(t,r,o,i){var a,s,p=this.actions,c=e(t)?t:"",u=r||{},f=e(o)?o:"",l=new n(c,u,f,i);p.length>=(null!==(s=null===(a=this._client)||void 0===a?void 0:a._config.maxActions)&&void 0!==s?s:30)&&p.shift(),p.push(l)},r.prototype.getUser=function(){return this.user},r.prototype.setUser=function(e){var n,r,o;if(r=e,"[object Object]"===Object.prototype.toString.call(r)&&Object.keys(e).length<=6)return this.user=t(t({},this.user),e),this.getUser();null===(n=this._client)||void 0===n||n._logger.warn((o=e,new Error("Invalid data\n- "+"setUser should be an object and have up to 6 attributes"+", got "+JSON.stringify(o))))},r.prototype.addMetaData=function(t,e){return function(t,e,n){e&&(t[e]=n)}(this.metaData,t,e)},r.prototype.getMetaData=function(t){return function(t,e){if(t[e])return t[e]}(this.metaData,t)},r.prototype.deleteMetaData=function(t){return function(t,e){if(t[e])return delete t[e]}(this.metaData,t)},r.prototype.toJSON=function(){var t=this;return{apiKey:t.apiKey,appVersion:t.appVersion,appType:t.appType,timestamp:t.timestamp,category:t.category,type:t.type,sdk:t.sdk,device:t.device,detail:t.detail,user:t.user,actions:t.actions,metaData:t.metaData,releaseStage:t.releaseStage}}}();
16
- /*! *****************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */
30
- var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function o(t,e){return function(e){function n(t){var n=e.call(this,t)||this;return n.state={error:null,info:null},n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,e),n.prototype.componentDidCatch=function(e,n){var r={name:e.name,message:e.message,stack:e.stack,errorInfo:n},o=t.createEvent({category:"error",type:"react",detail:r});t.notify(o),this.setState({error:e,info:n})},n.prototype.render=function(){if(this.state.error){var t=this.props.FallbackComponent;return t||null}return this.props.children},n}(e.Component)}return{name:"OhbugReact",init:function(t,e){if(!e)throw new Error("Ohbug @ohbug/react reference to `React` was undefined");return o(t,e)}}}));