@ohbug/extension-uuid 1.0.13 → 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,12 +2,11 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@ohbug/extension-uuid.svg?style=flat-square)](https://www.npmjs.com/package/@ohbug/extension-uuid)
4
4
  [![npm bundle size](https://img.shields.io/bundlephobia/min/@ohbug/extension-uuid?style=flat-square)](https://bundlephobia.com/result?p=@ohbug/extension-uuid)
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
  ## Installation
8
7
 
9
8
  ```
10
- yarn add @ohbug/extension-uuid
9
+ pnpm instal @ohbug/extension-uuid
11
10
  ```
12
11
 
13
12
  ## Usage
@@ -16,6 +15,6 @@ yarn add @ohbug/extension-uuid
16
15
  import Ohbug from '@ohbug/browser'
17
16
  import OhbugExtensionUUID from '@ohbug/extension-uuid'
18
17
 
19
- const client = Ohbug.init({ apiKey: 'YOUR_API_KEY' })
18
+ const client = Ohbug.setup({ apiKey: 'YOUR_API_KEY' })
20
19
  client.use(OhbugExtensionUUID)
21
20
  ```
package/dist/index.d.ts CHANGED
@@ -1,2 +1,166 @@
1
- export { extension as default } from './extension';
2
- //# sourceMappingURL=index.d.ts.map
1
+ interface OhbugAction {
2
+ type: string
3
+ timestamp: string
4
+ message?: string
5
+ data?: Record<string, any>
6
+ }
7
+
8
+ interface OhbugDevice {
9
+ // browser
10
+ language?: string
11
+ userAgent?: string
12
+ title?: string
13
+ url?: string
14
+
15
+ [key: string]: any
16
+ }
17
+
18
+ type OhbugGetDevice = (client?: OhbugClient) => OhbugDevice
19
+
20
+ interface OhbugUser {
21
+ uuid?: string
22
+ ip_address?: string
23
+ id?: number | string
24
+ name?: string
25
+ email?: string
26
+ [key: string]: any
27
+ }
28
+
29
+ type OhbugMetaData = Record<string, any>
30
+
31
+ type OhbugReleaseStage = 'development' | 'production' | string
32
+ type OhbugCategory =
33
+ | 'error'
34
+ | 'message'
35
+ | 'feedback'
36
+ | 'view'
37
+ | 'performance'
38
+ | 'other'
39
+ interface OhbugSDK {
40
+ platform: string
41
+ version: string
42
+ }
43
+
44
+ interface OhbugEvent<D> {
45
+ apiKey: string
46
+ appVersion?: string
47
+ appType?: string
48
+ releaseStage?: OhbugReleaseStage
49
+ timestamp: string
50
+ category?: OhbugCategory
51
+ type: string
52
+ sdk: OhbugSDK
53
+
54
+ detail: D
55
+ device: OhbugDevice
56
+ user?: OhbugUser
57
+ actions?: OhbugAction[]
58
+ metaData?: OhbugMetaData
59
+ }
60
+ interface OhbugEventWithMethods<D> extends OhbugEvent<D> {
61
+ addAction: (
62
+ message: string,
63
+ data: Record<string, any>,
64
+ type: string,
65
+ timestamp?: string
66
+ ) => void
67
+ getUser: () => OhbugUser | undefined
68
+ setUser: (user: OhbugUser) => OhbugUser | undefined
69
+ addMetaData: (section: string, data: any) => any
70
+ getMetaData: (section: string) => any
71
+ deleteMetaData: (section: string) => any
72
+ }
73
+
74
+ interface OhbugCreateEvent<D> {
75
+ category?: OhbugCategory
76
+ type: string
77
+ detail: D
78
+ }
79
+
80
+ interface OhbugExtension {
81
+ name: string
82
+ setup?: (client: OhbugClient, ...args: any[]) => void
83
+ onEvent?: <D = any>(
84
+ event: OhbugEventWithMethods<D>,
85
+ client: OhbugClient
86
+ ) => OhbugEventWithMethods<D> | null
87
+ onNotify?: <D = any>(
88
+ event: OhbugEventWithMethods<D>,
89
+ client: OhbugClient
90
+ ) => void
91
+ }
92
+
93
+ interface OhbugLoggerConfig {
94
+ log: (...args: any[]) => void
95
+ info: (...args: any[]) => void
96
+ warn: (...args: any[]) => void
97
+ error: (...args: any[]) => void
98
+ }
99
+
100
+ interface OhbugConfig {
101
+ // base
102
+ apiKey: string
103
+ appVersion?: string
104
+ appType?: string
105
+ releaseStage?: OhbugReleaseStage
106
+ endpoint?: string
107
+ maxActions?: number
108
+ // hooks
109
+ onEvent?: <D = any>(
110
+ event: OhbugEventWithMethods<D>,
111
+ client: OhbugClient
112
+ ) => OhbugEventWithMethods<D> | null
113
+ onNotify?: <D = any>(
114
+ event: OhbugEventWithMethods<D>,
115
+ client: OhbugClient
116
+ ) => void
117
+ // data
118
+ user?: OhbugUser
119
+ metaData?: OhbugMetaData
120
+ // utils
121
+ logger?: OhbugLoggerConfig
122
+ }
123
+
124
+ type OhbugNotifier = <D = any>(
125
+ event: OhbugEventWithMethods<D>
126
+ ) => Promise<any> | any
127
+
128
+ interface OhbugClient {
129
+ readonly __sdk: OhbugSDK
130
+ readonly __config: OhbugConfig
131
+ readonly __logger: OhbugLoggerConfig
132
+ readonly __device: OhbugGetDevice
133
+ readonly __notifier: OhbugNotifier
134
+
135
+ readonly __extensions: OhbugExtension[]
136
+
137
+ readonly __actions: OhbugAction[]
138
+ __user: OhbugUser
139
+ readonly __metaData: OhbugMetaData
140
+
141
+ use: (extension: OhbugExtension) => OhbugClient
142
+ createEvent: <D = any>(
143
+ value: OhbugCreateEvent<D>
144
+ ) => OhbugEventWithMethods<D> | null
145
+ notify: <D = any>(
146
+ eventLike: any,
147
+ beforeNotify?: (
148
+ event: OhbugEventWithMethods<D> | null
149
+ ) => OhbugEventWithMethods<D> | null
150
+ ) => Promise<any | null>
151
+ addAction: (
152
+ message: string,
153
+ data: Record<string, any>,
154
+ type: string,
155
+ timestamp?: string
156
+ ) => void
157
+ getUser: () => OhbugUser | undefined
158
+ setUser: (user: OhbugUser) => OhbugUser | undefined
159
+ addMetaData: (section: string, data: any) => any
160
+ getMetaData: (section: string) => any
161
+ deleteMetaData: (section: string) => any
162
+ }
163
+
164
+ declare const extension: OhbugExtension;
165
+
166
+ export { extension as default };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var t in r)m(e,t,{get:r[t],enumerable:!0})},b=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of U(r))!l.call(e,o)&&o!==t&&m(e,o,{get:()=>r[o],enumerable:!(n=I(r,o))||n.enumerable});return e};var T=e=>b(m({},"__esModule",{value:!0}),e);var D={};k(D,{default:()=>C});module.exports=T(D);var f=require("@ohbug/core");var a=require("uuid"),s=require("@ohbug/utils");var u={getItem(e){return decodeURIComponent(document.cookie.replace(new RegExp(`(?:(?:^|.*;)\\s*${encodeURIComponent(e).replace(/[-.+*]/g,"\\$&")}\\s*\\=\\s*([^;]*).*$)|^.*$`),"$1"))||null},setItem(e,r,t,n,o,d){if(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))return!1;let i="";if(t)switch(t.constructor){case Number:i=t===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":`; max-age=${t}`;break;case String:i=`; expires=${t}`;break;case Date:i=`; expires=${t.toUTCString()}`;break;default:break}let p=`${encodeURIComponent(e)}=${encodeURIComponent(r)}${i}${o?`; domain=${o}`:""}${n?`; path=${n}`:""}${d?"; secure":""}`;return document.cookie=p,p},removeItem(e,r,t){return!e||!this.getItem(e)?!1:(document.cookie=`${encodeURIComponent(e)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${t?`; domain=${t}`:""}${r?`; path=${r}`:""}`,!0)}};var g="OhbugUUID";function $(){if((0,s.isBrowser)()){let e=u.getItem(g);if(!e){let t=new Date;t.setTime(t.getTime()+15552e7);let n=(0,a.v4)();return u.setItem(g,n,t),n}return e}return(0,s.isNode)()?(0,a.v4)():""}var x=(0,f.defineExtension)({name:"OhbugExtensionUUID",onEvent:e=>{let r=$();return e.setUser({uuid:r}),e}});var C=x;0&&(module.exports={});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{defineExtension as I}from"@ohbug/core";import{v4 as a}from"uuid";import{isBrowser as x,isNode as d}from"@ohbug/utils";var m={getItem(e){return decodeURIComponent(document.cookie.replace(new RegExp(`(?:(?:^|.*;)\\s*${encodeURIComponent(e).replace(/[-.+*]/g,"\\$&")}\\s*\\=\\s*([^;]*).*$)|^.*$`),"$1"))||null},setItem(e,r,t,n,c,f){if(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))return!1;let o="";if(t)switch(t.constructor){case Number:o=t===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":`; max-age=${t}`;break;case String:o=`; expires=${t}`;break;case Date:o=`; expires=${t.toUTCString()}`;break;default:break}let u=`${encodeURIComponent(e)}=${encodeURIComponent(r)}${o}${c?`; domain=${c}`:""}${n?`; path=${n}`:""}${f?"; secure":""}`;return document.cookie=u,u},removeItem(e,r,t){return!e||!this.getItem(e)?!1:(document.cookie=`${encodeURIComponent(e)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${t?`; domain=${t}`:""}${r?`; path=${r}`:""}`,!0)}};var p="OhbugUUID";function g(){if(x()){let e=m.getItem(p);if(!e){let t=new Date;t.setTime(t.getTime()+15552e7);let n=a();return m.setItem(p,n,t),n}return e}return d()?a():""}var $=I({name:"OhbugExtensionUUID",onEvent:e=>{let r=g();return e.setUser({uuid:r}),e}});var w=$;export{w as default};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@ohbug/extension-uuid",
3
- "version": "1.0.13",
3
+ "version": "2.0.1",
4
4
  "description": "Ohbug extension to add uuid",
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,38 +12,33 @@
11
12
  "type": "git",
12
13
  "url": "https://github.com/ohbug-org/ohbug"
13
14
  },
14
- "license": "Apache-2.0",
15
- "main": "./dist/ohbug-extension-uuid.umd.js",
16
- "module": "./dist/ohbug-extension-uuid.es.js",
17
- "unpkg": "./dist/ohbug-extension-uuid.umd.js",
18
- "jsdelivr": "./dist/ohbug-extension-uuid.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-extension-uuid.es.js",
23
- "require": "./dist/ohbug-extension-uuid.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
  ],
28
+ "sideEffects": false,
29
29
  "dependencies": {
30
- "@ohbug/core": "^1.1.6",
31
- "@ohbug/utils": "^1.0.13",
30
+ "@ohbug/core": "2.0.1",
31
+ "@ohbug/utils": "2.0.1",
32
32
  "uuid": "^8.3.2"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/uuid": "^8.0.0"
36
36
  },
37
- "buildOptions": {
38
- "name": "OhbugExtensionUUID",
39
- "formats": [
40
- "es",
41
- "umd"
42
- ]
43
- },
44
37
  "publishConfig": {
45
38
  "access": "public"
46
39
  },
47
- "gitHead": "10a43cc9dc7cceec6a209746b0258de14390aa32"
48
- }
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "dev": "tsup --watch"
43
+ }
44
+ }
package/dist/cookie.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare const docCookies: {
2
- getItem(sKey: string): string | null;
3
- setItem(sKey: string, sValue: string, vEnd?: string | number | Date | undefined, sPath?: string | undefined, sDomain?: string | undefined, bSecure?: boolean | undefined): string | false;
4
- removeItem(sKey: string, sPath?: string | undefined, sDomain?: string | undefined): boolean;
5
- };
6
- //# sourceMappingURL=cookie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../src/cookie.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU;kBACP,MAAM,GAAG,MAAM,GAAG,IAAI;kBAgB5B,MAAM,UACJ,MAAM,uIAKb,MAAM,GAAG,KAAK;qBAiCA,MAAM;CAWxB,CAAA"}
@@ -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":"AAGA,eAAO,MAAM,SAAS,4CASpB,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,aAAa,CAAA"}
@@ -1,352 +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
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
187
- // require the crypto API and do not support built-in fallback to lower quality random number
188
- // generators (like Math.random()).
189
- var getRandomValues;
190
- var rnds8 = new Uint8Array(16);
191
- function rng() {
192
- // lazy load so that environments that need to polyfill have a chance to do so
193
- if (!getRandomValues) {
194
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
195
- // find the complete implementation of crypto (msCrypto) on IE11.
196
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
197
-
198
- if (!getRandomValues) {
199
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
200
- }
201
- }
202
-
203
- return getRandomValues(rnds8);
204
- }
205
-
206
- var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
207
-
208
- function validate(uuid) {
209
- return typeof uuid === 'string' && REGEX.test(uuid);
210
- }
211
-
212
- /**
213
- * Convert array of 16 byte values to UUID string format of the form:
214
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
215
- */
216
-
217
- var byteToHex = [];
218
-
219
- for (var i = 0; i < 256; ++i) {
220
- byteToHex.push((i + 0x100).toString(16).substr(1));
221
- }
222
-
223
- function stringify(arr) {
224
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
225
- // Note: Be careful editing this code! It's been tuned for performance
226
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
227
- var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
228
- // of the following:
229
- // - One or more input array values don't map to a hex octet (leading to
230
- // "undefined" in the uuid)
231
- // - Invalid input values for the RFC `version` or `variant` fields
232
-
233
- if (!validate(uuid)) {
234
- throw TypeError('Stringified UUID is invalid');
235
- }
236
-
237
- return uuid;
238
- }
239
-
240
- function v4(options, buf, offset) {
241
- options = options || {};
242
- var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
243
-
244
- rnds[6] = rnds[6] & 0x0f | 0x40;
245
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
246
-
247
- if (buf) {
248
- offset = offset || 0;
249
-
250
- for (var i = 0; i < 16; ++i) {
251
- buf[offset + i] = rnds[i];
252
- }
253
-
254
- return buf;
255
- }
256
-
257
- return stringify(rnds);
258
- }
259
-
260
- /*! *****************************************************************************
261
- Copyright (c) Microsoft Corporation.
262
-
263
- Permission to use, copy, modify, and/or distribute this software for any
264
- purpose with or without fee is hereby granted.
265
-
266
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
267
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
268
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
269
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
270
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
271
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272
- PERFORMANCE OF THIS SOFTWARE.
273
- ***************************************************************************** */
274
- function isNode() {
275
- return typeof global !== 'undefined';
276
- }
277
- function isBrowser() {
278
- return typeof window !== 'undefined';
279
- }
280
-
281
- // https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie
282
- var docCookies = {
283
- getItem: function (sKey) {
284
- return (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + "\\s*\\=\\s*([^;]*).*$)|^.*$"), '$1')) || null);
285
- },
286
- setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
287
- // eslint-disable-next-line
288
- if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
289
- return false;
290
- }
291
- var sExpires = '';
292
- if (vEnd) {
293
- switch (vEnd.constructor) {
294
- case Number:
295
- sExpires =
296
- vEnd === Infinity
297
- ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT'
298
- : "; max-age=" + vEnd;
299
- break;
300
- case String:
301
- sExpires = "; expires=" + vEnd;
302
- break;
303
- case Date:
304
- sExpires = "; expires=" + vEnd.toUTCString();
305
- break;
306
- }
307
- }
308
- var value = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : '') + (sPath ? "; path=" + sPath : '') + (bSecure ? '; secure' : '');
309
- document.cookie = value;
310
- return value;
311
- },
312
- removeItem: function (sKey, sPath, sDomain) {
313
- if (!sKey || !this.getItem(sKey)) {
314
- return false;
315
- }
316
- document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : '') + (sPath ? "; path=" + sPath : '');
317
- return true;
318
- },
319
- };
320
-
321
- var key = 'OhbugUUID';
322
- function getUUID() {
323
- if (isBrowser()) {
324
- var UUID = docCookies.getItem(key);
325
- if (!UUID) {
326
- var extraTime = 60 * 30 * 24 * 3600 * 1000; // 30天后过期
327
- var endTime = new Date();
328
- endTime.setTime(endTime.getTime() + extraTime);
329
- var uuid = v4();
330
- docCookies.setItem(key, uuid, endTime);
331
- return uuid;
332
- }
333
- return UUID;
334
- }
335
- if (isNode()) {
336
- return v4();
337
- }
338
- return '';
339
- }
340
-
341
- var extension = createExtension({
342
- name: 'OhbugExtensionUUID',
343
- created: function (event) {
344
- var uuid = getUUID();
345
- event.setUser({
346
- uuid: uuid,
347
- });
348
- return event;
349
- },
350
- });
351
-
352
- export { extension as default };
@@ -1,29 +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 a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};function e(t){return"string"==typeof t}var r,n=function(t,e,r,n){this.type=r,this.timestamp=n||(new Date).toISOString(),this.message=t,this.data=e};!function(){function r(t,e){var r=t.apiKey,n=t.appVersion,a=t.appType,i=t.releaseStage,o=t.timestamp,s=t.category,u=t.type,p=t.sdk,c=t.detail,d=t.device,f=t.user,h=t.actions,g=t.metaData;this.apiKey=r,this.appVersion=n,this.appType=a,this.releaseStage=i,this.timestamp=o,this.category=s,this.type=u,this.sdk=p,this.detail=c,this.device=d,this.user=f,this.actions=h,this.metaData=g,this._client=e}Object.defineProperty(r.prototype,"_isOhbugEvent",{get:function(){return!0},enumerable:!1,configurable:!0}),r.prototype.addAction=function(t,r,a,i){var o,s,u=this.actions,p=e(t)?t:"",c=r||{},d=e(a)?a:"",f=new n(p,c,d,i);u.length>=(null!==(s=null===(o=this._client)||void 0===o?void 0:o._config.maxActions)&&void 0!==s?s:30)&&u.shift(),u.push(f)},r.prototype.getUser=function(){return this.user},r.prototype.setUser=function(e){var r,n,a;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((a=e,new Error("Invalid data\n- "+"setUser should be an object and have up to 6 attributes"+", got "+JSON.stringify(a))))},r.prototype.addMetaData=function(t,e){return function(t,e,r){e&&(t[e]=r)}(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}}}();var a=new Uint8Array(16);function i(){if(!r&&!(r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return r(a)}var o=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function s(t){return"string"==typeof t&&o.test(t)}for(var u=[],p=0;p<256;++p)u.push((p+256).toString(16).substr(1));function c(t,e,r){var n=(t=t||{}).random||(t.rng||i)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){r=r||0;for(var a=0;a<16;++a)e[r+a]=n[a];return e}return function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(u[t[e+0]]+u[t[e+1]]+u[t[e+2]]+u[t[e+3]]+"-"+u[t[e+4]]+u[t[e+5]]+"-"+u[t[e+6]]+u[t[e+7]]+"-"+u[t[e+8]]+u[t[e+9]]+"-"+u[t[e+10]]+u[t[e+11]]+u[t[e+12]]+u[t[e+13]]+u[t[e+14]]+u[t[e+15]]).toLowerCase();if(!s(r))throw TypeError("Stringified UUID is invalid");return r}(n)}
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
- ***************************************************************************** */var d=function(t){return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(t).replace(/[-.+*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},f=function(t,e,r,n,a,i){if(!t||/^(?:expires|max\-age|path|domain|secure)$/i.test(t))return!1;var o="";if(r)switch(r.constructor){case Number:o=r===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+r;break;case String:o="; expires="+r;break;case Date:o="; expires="+r.toUTCString()}var s=encodeURIComponent(t)+"="+encodeURIComponent(e)+o+(a?"; domain="+a:"")+(n?"; path="+n:"")+(i?"; secure":"");return document.cookie=s,s};function h(){if("undefined"!=typeof window){var t=d("OhbugUUID");if(!t){var e=new Date;e.setTime(e.getTime()+15552e7);var r=c();return f("OhbugUUID",r,e),r}return t}return"undefined"!=typeof global?c():""}var g={name:"OhbugExtensionUUID",created:function(t){var e=h();return t.setUser({uuid:e}),t}};export{g as default};
@@ -1,360 +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.OhbugExtensionUUID = 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
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
193
- // require the crypto API and do not support built-in fallback to lower quality random number
194
- // generators (like Math.random()).
195
- var getRandomValues;
196
- var rnds8 = new Uint8Array(16);
197
- function rng() {
198
- // lazy load so that environments that need to polyfill have a chance to do so
199
- if (!getRandomValues) {
200
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
201
- // find the complete implementation of crypto (msCrypto) on IE11.
202
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
203
-
204
- if (!getRandomValues) {
205
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
206
- }
207
- }
208
-
209
- return getRandomValues(rnds8);
210
- }
211
-
212
- var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
213
-
214
- function validate(uuid) {
215
- return typeof uuid === 'string' && REGEX.test(uuid);
216
- }
217
-
218
- /**
219
- * Convert array of 16 byte values to UUID string format of the form:
220
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
221
- */
222
-
223
- var byteToHex = [];
224
-
225
- for (var i = 0; i < 256; ++i) {
226
- byteToHex.push((i + 0x100).toString(16).substr(1));
227
- }
228
-
229
- function stringify(arr) {
230
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
231
- // Note: Be careful editing this code! It's been tuned for performance
232
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
233
- var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
234
- // of the following:
235
- // - One or more input array values don't map to a hex octet (leading to
236
- // "undefined" in the uuid)
237
- // - Invalid input values for the RFC `version` or `variant` fields
238
-
239
- if (!validate(uuid)) {
240
- throw TypeError('Stringified UUID is invalid');
241
- }
242
-
243
- return uuid;
244
- }
245
-
246
- function v4(options, buf, offset) {
247
- options = options || {};
248
- var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
249
-
250
- rnds[6] = rnds[6] & 0x0f | 0x40;
251
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
252
-
253
- if (buf) {
254
- offset = offset || 0;
255
-
256
- for (var i = 0; i < 16; ++i) {
257
- buf[offset + i] = rnds[i];
258
- }
259
-
260
- return buf;
261
- }
262
-
263
- return stringify(rnds);
264
- }
265
-
266
- /*! *****************************************************************************
267
- Copyright (c) Microsoft Corporation.
268
-
269
- Permission to use, copy, modify, and/or distribute this software for any
270
- purpose with or without fee is hereby granted.
271
-
272
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
273
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
274
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
275
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
276
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
277
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
278
- PERFORMANCE OF THIS SOFTWARE.
279
- ***************************************************************************** */
280
- function isNode() {
281
- return typeof global !== 'undefined';
282
- }
283
- function isBrowser() {
284
- return typeof window !== 'undefined';
285
- }
286
-
287
- // https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie
288
- var docCookies = {
289
- getItem: function (sKey) {
290
- return (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + "\\s*\\=\\s*([^;]*).*$)|^.*$"), '$1')) || null);
291
- },
292
- setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
293
- // eslint-disable-next-line
294
- if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
295
- return false;
296
- }
297
- var sExpires = '';
298
- if (vEnd) {
299
- switch (vEnd.constructor) {
300
- case Number:
301
- sExpires =
302
- vEnd === Infinity
303
- ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT'
304
- : "; max-age=" + vEnd;
305
- break;
306
- case String:
307
- sExpires = "; expires=" + vEnd;
308
- break;
309
- case Date:
310
- sExpires = "; expires=" + vEnd.toUTCString();
311
- break;
312
- }
313
- }
314
- var value = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : '') + (sPath ? "; path=" + sPath : '') + (bSecure ? '; secure' : '');
315
- document.cookie = value;
316
- return value;
317
- },
318
- removeItem: function (sKey, sPath, sDomain) {
319
- if (!sKey || !this.getItem(sKey)) {
320
- return false;
321
- }
322
- document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : '') + (sPath ? "; path=" + sPath : '');
323
- return true;
324
- },
325
- };
326
-
327
- var key = 'OhbugUUID';
328
- function getUUID() {
329
- if (isBrowser()) {
330
- var UUID = docCookies.getItem(key);
331
- if (!UUID) {
332
- var extraTime = 60 * 30 * 24 * 3600 * 1000; // 30天后过期
333
- var endTime = new Date();
334
- endTime.setTime(endTime.getTime() + extraTime);
335
- var uuid = v4();
336
- docCookies.setItem(key, uuid, endTime);
337
- return uuid;
338
- }
339
- return UUID;
340
- }
341
- if (isNode()) {
342
- return v4();
343
- }
344
- return '';
345
- }
346
-
347
- var extension = createExtension({
348
- name: 'OhbugExtensionUUID',
349
- created: function (event) {
350
- var uuid = getUUID();
351
- event.setUser({
352
- uuid: uuid,
353
- });
354
- return event;
355
- },
356
- });
357
-
358
- return extension;
359
-
360
- })));
@@ -1,29 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).OhbugExtensionUUID=t()}(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 e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function t(e){return"string"==typeof e}var n,r=function(e,t,n,r){this.type=n,this.timestamp=r||(new Date).toISOString(),this.message=e,this.data=t};!function(){function n(e,t){var n=e.apiKey,r=e.appVersion,i=e.appType,o=e.releaseStage,a=e.timestamp,s=e.category,u=e.type,p=e.sdk,c=e.detail,f=e.device,d=e.user,h=e.actions,y=e.metaData;this.apiKey=n,this.appVersion=r,this.appType=i,this.releaseStage=o,this.timestamp=a,this.category=s,this.type=u,this.sdk=p,this.detail=c,this.device=f,this.user=d,this.actions=h,this.metaData=y,this._client=t}Object.defineProperty(n.prototype,"_isOhbugEvent",{get:function(){return!0},enumerable:!1,configurable:!0}),n.prototype.addAction=function(e,n,i,o){var a,s,u=this.actions,p=t(e)?e:"",c=n||{},f=t(i)?i:"",d=new r(p,c,f,o);u.length>=(null!==(s=null===(a=this._client)||void 0===a?void 0:a._config.maxActions)&&void 0!==s?s:30)&&u.shift(),u.push(d)},n.prototype.getUser=function(){return this.user},n.prototype.setUser=function(t){var n,r,i;if(r=t,"[object Object]"===Object.prototype.toString.call(r)&&Object.keys(t).length<=6)return this.user=e(e({},this.user),t),this.getUser();null===(n=this._client)||void 0===n||n._logger.warn((i=t,new Error("Invalid data\n- "+"setUser should be an object and have up to 6 attributes"+", got "+JSON.stringify(i))))},n.prototype.addMetaData=function(e,t){return function(e,t,n){t&&(e[t]=n)}(this.metaData,e,t)},n.prototype.getMetaData=function(e){return function(e,t){if(e[t])return e[t]}(this.metaData,e)},n.prototype.deleteMetaData=function(e){return function(e,t){if(e[t])return delete e[t]}(this.metaData,e)},n.prototype.toJSON=function(){var e=this;return{apiKey:e.apiKey,appVersion:e.appVersion,appType:e.appType,timestamp:e.timestamp,category:e.category,type:e.type,sdk:e.sdk,device:e.device,detail:e.detail,user:e.user,actions:e.actions,metaData:e.metaData,releaseStage:e.releaseStage}}}();var i=new Uint8Array(16);function o(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(i)}var a=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function s(e){return"string"==typeof e&&a.test(e)}for(var u=[],p=0;p<256;++p)u.push((p+256).toString(16).substr(1));function c(e,t,n){var r=(e=e||{}).random||(e.rng||o)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(u[e[t+0]]+u[e[t+1]]+u[e[t+2]]+u[e[t+3]]+"-"+u[e[t+4]]+u[e[t+5]]+"-"+u[e[t+6]]+u[e[t+7]]+"-"+u[e[t+8]]+u[e[t+9]]+"-"+u[e[t+10]]+u[e[t+11]]+u[e[t+12]]+u[e[t+13]]+u[e[t+14]]+u[e[t+15]]).toLowerCase();if(!s(n))throw TypeError("Stringified UUID is invalid");return n}(r)}
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
- ***************************************************************************** */var f=function(e){return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(e).replace(/[-.+*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},d=function(e,t,n,r,i,o){if(!e||/^(?:expires|max\-age|path|domain|secure)$/i.test(e))return!1;var a="";if(n)switch(n.constructor){case Number:a=n===1/0?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+n;break;case String:a="; expires="+n;break;case Date:a="; expires="+n.toUTCString()}var s=encodeURIComponent(e)+"="+encodeURIComponent(t)+a+(i?"; domain="+i:"")+(r?"; path="+r:"")+(o?"; secure":"");return document.cookie=s,s},h="OhbugUUID";function y(){if("undefined"!=typeof window){var e=f(h);if(!e){var t=new Date;t.setTime(t.getTime()+15552e7);var n=c();return d(h,n,t),n}return e}return"undefined"!=typeof global?c():""}return{name:"OhbugExtensionUUID",created:function(e){var t=y();return e.setUser({uuid:t}),e}}}));
package/dist/uuid.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function getUUID(): string;
2
- //# sourceMappingURL=uuid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAMA,wBAAgB,OAAO,IAAI,MAAM,CAiBhC"}