@ohbug/extension-uuid 1.0.12 → 2.0.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.
@@ -1,354 +0,0 @@
1
- 'use strict';
2
-
3
- /*! *****************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
-
18
- var __assign = function() {
19
- __assign = Object.assign || function __assign(t) {
20
- for (var s, i = 1, n = arguments.length; i < n; i++) {
21
- s = arguments[i];
22
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
-
29
- function isString(value) {
30
- return typeof value === 'string';
31
- }
32
- function isObject(value) {
33
- return Object.prototype.toString.call(value) === '[object Object]';
34
- }
35
-
36
- function createExtension(extension) {
37
- return extension;
38
- }
39
-
40
- var Action = /** @class */ (function () {
41
- function Action(message, data, type, timestamp) {
42
- this.type = type;
43
- this.timestamp = timestamp || new Date().toISOString();
44
- this.message = message;
45
- this.data = data;
46
- }
47
- return Action;
48
- }());
49
- function getErrorMessage(message, data) {
50
- return new Error("Invalid data\n- " + message + ", got " + JSON.stringify(data));
51
- }
52
-
53
- function addMetaData(map, section, data) {
54
- if (!section)
55
- return;
56
- map[section] = data;
57
- }
58
- function getMetaData(map, section) {
59
- if (map[section]) {
60
- return map[section];
61
- }
62
- return undefined;
63
- }
64
- function deleteMetaData(map, section) {
65
- if (map[section]) {
66
- return delete map[section];
67
- }
68
- return undefined;
69
- }
70
-
71
- /** @class */ ((function () {
72
- function Event(values, client) {
73
- 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;
74
- this.apiKey = apiKey;
75
- this.appVersion = appVersion;
76
- this.appType = appType;
77
- this.releaseStage = releaseStage;
78
- this.timestamp = timestamp;
79
- this.category = category;
80
- this.type = type;
81
- this.sdk = sdk;
82
- this.detail = detail;
83
- this.device = device;
84
- this.user = user;
85
- this.actions = actions;
86
- this.metaData = metaData;
87
- this._client = client;
88
- }
89
- Object.defineProperty(Event.prototype, "_isOhbugEvent", {
90
- get: function () {
91
- return true;
92
- },
93
- enumerable: false,
94
- configurable: true
95
- });
96
- /**
97
- * Add an action.
98
- * Once the threshold is reached, the oldest breadcrumbs will be deleted.
99
- * 新增一个动作。
100
- * 一旦达到阈值,最老的 Action 将被删除。
101
- *
102
- * @param message
103
- * @param data
104
- * @param type
105
- * @param timestamp
106
- */
107
- Event.prototype.addAction = function (message, data, type, timestamp) {
108
- var _a, _b;
109
- var actions = this.actions;
110
- var targetMessage = isString(message) ? message : '';
111
- var targetData = data || {};
112
- var targetType = isString(type) ? type : '';
113
- var action = new Action(targetMessage, targetData, targetType, timestamp);
114
- if (actions.length >= ((_b = (_a = this._client) === null || _a === void 0 ? void 0 : _a._config.maxActions) !== null && _b !== void 0 ? _b : 30)) {
115
- actions.shift();
116
- }
117
- actions.push(action);
118
- };
119
- /**
120
- * Get current user information
121
- * 获取当前的用户信息
122
- */
123
- Event.prototype.getUser = function () {
124
- return this.user;
125
- };
126
- /**
127
- * Set current user information
128
- * 设置当前的用户信息
129
- */
130
- Event.prototype.setUser = function (user) {
131
- var _a;
132
- if (isObject(user) && Object.keys(user).length <= 6) {
133
- this.user = __assign(__assign({}, this.user), user);
134
- return this.getUser();
135
- }
136
- (_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));
137
- return undefined;
138
- };
139
- /**
140
- * Add metaData
141
- * 新增 metaData
142
- *
143
- * @param section
144
- * @param data
145
- */
146
- Event.prototype.addMetaData = function (section, data) {
147
- return addMetaData(this.metaData, section, data);
148
- };
149
- /**
150
- * Get metaData
151
- * 获取 metaData
152
- *
153
- * @param section
154
- */
155
- Event.prototype.getMetaData = function (section) {
156
- return getMetaData(this.metaData, section);
157
- };
158
- /**
159
- * Delete metaData
160
- * 删除 metaData
161
- *
162
- * @param section
163
- */
164
- Event.prototype.deleteMetaData = function (section) {
165
- return deleteMetaData(this.metaData, section);
166
- };
167
- Event.prototype.toJSON = function () {
168
- 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;
169
- return {
170
- apiKey: apiKey,
171
- appVersion: appVersion,
172
- appType: appType,
173
- timestamp: timestamp,
174
- category: category,
175
- type: type,
176
- sdk: sdk,
177
- device: device,
178
- detail: detail,
179
- user: user,
180
- actions: actions,
181
- metaData: metaData,
182
- releaseStage: releaseStage,
183
- };
184
- };
185
- return Event;
186
- })());
187
-
188
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
189
- // require the crypto API and do not support built-in fallback to lower quality random number
190
- // generators (like Math.random()).
191
- var getRandomValues;
192
- var rnds8 = new Uint8Array(16);
193
- function rng() {
194
- // lazy load so that environments that need to polyfill have a chance to do so
195
- if (!getRandomValues) {
196
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
197
- // find the complete implementation of crypto (msCrypto) on IE11.
198
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
199
-
200
- if (!getRandomValues) {
201
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
202
- }
203
- }
204
-
205
- return getRandomValues(rnds8);
206
- }
207
-
208
- 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;
209
-
210
- function validate(uuid) {
211
- return typeof uuid === 'string' && REGEX.test(uuid);
212
- }
213
-
214
- /**
215
- * Convert array of 16 byte values to UUID string format of the form:
216
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
217
- */
218
-
219
- var byteToHex = [];
220
-
221
- for (var i = 0; i < 256; ++i) {
222
- byteToHex.push((i + 0x100).toString(16).substr(1));
223
- }
224
-
225
- function stringify(arr) {
226
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
227
- // Note: Be careful editing this code! It's been tuned for performance
228
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
229
- 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
230
- // of the following:
231
- // - One or more input array values don't map to a hex octet (leading to
232
- // "undefined" in the uuid)
233
- // - Invalid input values for the RFC `version` or `variant` fields
234
-
235
- if (!validate(uuid)) {
236
- throw TypeError('Stringified UUID is invalid');
237
- }
238
-
239
- return uuid;
240
- }
241
-
242
- function v4(options, buf, offset) {
243
- options = options || {};
244
- var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
245
-
246
- rnds[6] = rnds[6] & 0x0f | 0x40;
247
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
248
-
249
- if (buf) {
250
- offset = offset || 0;
251
-
252
- for (var i = 0; i < 16; ++i) {
253
- buf[offset + i] = rnds[i];
254
- }
255
-
256
- return buf;
257
- }
258
-
259
- return stringify(rnds);
260
- }
261
-
262
- /*! *****************************************************************************
263
- Copyright (c) Microsoft Corporation.
264
-
265
- Permission to use, copy, modify, and/or distribute this software for any
266
- purpose with or without fee is hereby granted.
267
-
268
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
269
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
270
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
271
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
273
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
274
- PERFORMANCE OF THIS SOFTWARE.
275
- ***************************************************************************** */
276
- function isNode() {
277
- return typeof global !== 'undefined';
278
- }
279
- function isBrowser() {
280
- return typeof window !== 'undefined';
281
- }
282
-
283
- // https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie
284
- var docCookies = {
285
- getItem: function (sKey) {
286
- return (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + "\\s*\\=\\s*([^;]*).*$)|^.*$"), '$1')) || null);
287
- },
288
- setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
289
- // eslint-disable-next-line
290
- if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
291
- return false;
292
- }
293
- var sExpires = '';
294
- if (vEnd) {
295
- switch (vEnd.constructor) {
296
- case Number:
297
- sExpires =
298
- vEnd === Infinity
299
- ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT'
300
- : "; max-age=" + vEnd;
301
- break;
302
- case String:
303
- sExpires = "; expires=" + vEnd;
304
- break;
305
- case Date:
306
- sExpires = "; expires=" + vEnd.toUTCString();
307
- break;
308
- }
309
- }
310
- var value = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : '') + (sPath ? "; path=" + sPath : '') + (bSecure ? '; secure' : '');
311
- document.cookie = value;
312
- return value;
313
- },
314
- removeItem: function (sKey, sPath, sDomain) {
315
- if (!sKey || !this.getItem(sKey)) {
316
- return false;
317
- }
318
- document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : '') + (sPath ? "; path=" + sPath : '');
319
- return true;
320
- },
321
- };
322
-
323
- var key = 'OhbugUUID';
324
- function getUUID() {
325
- if (isBrowser()) {
326
- var UUID = docCookies.getItem(key);
327
- if (!UUID) {
328
- var extraTime = 60 * 30 * 24 * 3600 * 1000; // 30天后过期
329
- var endTime = new Date();
330
- endTime.setTime(endTime.getTime() + extraTime);
331
- var uuid = v4();
332
- docCookies.setItem(key, uuid, endTime);
333
- return uuid;
334
- }
335
- return UUID;
336
- }
337
- if (isNode()) {
338
- return v4();
339
- }
340
- return '';
341
- }
342
-
343
- var extension = createExtension({
344
- name: 'OhbugExtensionUUID',
345
- created: function (event) {
346
- var uuid = getUUID();
347
- event.setUser({
348
- uuid: uuid,
349
- });
350
- return event;
351
- },
352
- });
353
-
354
- module.exports = extension;
@@ -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 default extension;