Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 0ff26d2

Browse files
committed
chore(deps): update uuid to v8 since v3.4 is deprecated
1 parent 7558b32 commit 0ff26d2

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
⚠️ Be sure to check out the next generation of analytics.js! https://github.com/segmentio/analytics-next 🎉
1+
⚠️ Be sure to check out the next generation of analytics.js! https://github.com/segmentio/analytics-next 🎉
22
If you have an existing JavaScript source with Segment, you can enable Analytics Next in the settings of the source.
33

44
# analytics.js-core
@@ -37,46 +37,49 @@ declare global {
3737
```
3838

3939
## Using as a standalone `npm` package
40-
We recommend using the CDN version of `analytics.js` as it offers all the project and workspace specific settings, enabled integrations, and middleware. But if you prefer to use `analytics.js-core` as a standalone npm package using your own tooling & workflow, you can do the following:
4140

42-
1- Install the dependencies
41+
We recommend using the CDN version of `analytics.js` as it offers all the project and workspace specific settings, enabled integrations, and middleware. But if you prefer to use `analytics.js-core` as a standalone npm package using your own tooling & workflow, you can do the following:
42+
43+
1- Install the dependencies
44+
4345
```
4446
yarn add @segment/analytics.js-core
4547
yarn add @segment/analytics.js-integration-segmentio
4648
// you may need this depending on the bundler
47-
yarn add uuid@^3.4
49+
yarn add uuid@^8.0.0
4850
```
4951

50-
2- Import the dependencies
52+
2- Import the dependencies
53+
5154
```javascript
52-
import Analytics from "@segment/analytics.js-core/build/analytics";
53-
import SegmentIntegration from "@segment/analytics.js-integration-segmentio";
55+
import Analytics from '@segment/analytics.js-core/build/analytics';
56+
import SegmentIntegration from '@segment/analytics.js-integration-segmentio';
5457
```
5558

56-
3- Initialize Segment and add Segment's own integration
59+
3- Initialize Segment and add Segment's own integration
60+
5761
```javascript
5862
// instantiate the library
5963
const analytics = new Analytics();
6064

61-
// add Segment's own integration ( or any other device mode integration )
65+
// add Segment's own integration ( or any other device mode integration )
6266
analytics.use(SegmentIntegration);
6367

64-
// define the integration settings object.
65-
// Since we are using only Segment integration in this example, we only have
68+
// define the integration settings object.
69+
// Since we are using only Segment integration in this example, we only have
6670
// "Segment.io" in the integrationSettings object
6771
const integrationSettings = {
68-
"Segment.io": {
69-
apiKey: "<YOUR SEGMENT WRITE KEY>",
72+
'Segment.io': {
73+
apiKey: '<YOUR SEGMENT WRITE KEY>',
7074
retryQueue: true,
71-
addBundledMetadata: true
72-
}
75+
addBundledMetadata: true,
76+
},
7377
};
7478

75-
7679
// Initialize the library
7780
analytics.initialize(integrationSettings);
7881

79-
// Happy tracking!
82+
// Happy tracking!
8083
analytics.track('🚀');
8184
```
8285

lib/normalize.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var each = require('./utils/each');
1212
var includes = require('@ndhoule/includes');
1313
var map = require('./utils/map');
1414
var type = require('component-type');
15-
var uuid = require('uuid/v4');
15+
var { v4: uuidv4 } = require('uuid');
1616
var md5 = require('spark-md5').hash;
1717

1818
/**
@@ -45,7 +45,7 @@ interface NormalizedMessage {
4545
}
4646

4747
function normalize(msg: Message, list: Array<any>): NormalizedMessage {
48-
var lower = map(function(s) {
48+
var lower = map(function (s) {
4949
return s.toLowerCase();
5050
}, list);
5151
var opts: Message = msg.options || {};
@@ -59,15 +59,15 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
5959
debug('<-', msg);
6060

6161
// integrations.
62-
each(function(value: string, key: string) {
62+
each(function (value: string, key: string) {
6363
if (!integration(key)) return;
6464
if (!has.call(integrations, key)) integrations[key] = value;
6565
delete opts[key];
6666
}, opts);
6767

6868
// providers.
6969
delete opts.providers;
70-
each(function(value: string, key: string) {
70+
each(function (value: string, key: string) {
7171
if (!integration(key)) return;
7272
if (type(integrations[key]) === 'object') return;
7373
if (has.call(integrations, key) && typeof providers[key] === 'boolean')
@@ -77,7 +77,7 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
7777

7878
// move all toplevel options to msg
7979
// and the rest to context.
80-
each(function(_value: any, key: string | number) {
80+
each(function (_value: any, key: string | number) {
8181
if (includes(key, toplevel)) {
8282
ret[key] = opts[key];
8383
} else {
@@ -86,7 +86,7 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
8686
}, opts);
8787

8888
// generate and attach a messageId to msg
89-
msg.messageId = 'ajs-' + md5(window.JSON.stringify(msg) + uuid());
89+
msg.messageId = 'ajs-' + md5(window.JSON.stringify(msg) + uuidv4());
9090

9191
// cleanup
9292
delete msg.options;

lib/user.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var cookie = require('./cookie');
1111
var debug = require('debug')('analytics:user');
1212
var inherit = require('inherits');
1313
var rawCookie = require('@segment/cookie');
14-
var uuid = require('uuid');
14+
var { v4: uuidv4 } = require('uuid');
1515
var localStorage = require('./store');
1616

1717
/**
@@ -38,11 +38,11 @@ User.defaults = {
3838
persist: true,
3939
cookie: {
4040
key: 'ajs_user_id',
41-
oldKey: 'ajs_user'
41+
oldKey: 'ajs_user',
4242
},
4343
localStorage: {
44-
key: 'ajs_user_traits'
45-
}
44+
key: 'ajs_user_traits',
45+
},
4646
};
4747

4848
/**
@@ -86,7 +86,7 @@ inherit(User, Entity);
8686
* assert.notEqual(anonymousId, user.anonymousId());
8787
*/
8888

89-
User.prototype.id = function(id?: string): string | undefined {
89+
User.prototype.id = function (id?: string): string | undefined {
9090
var prev = this._getId();
9191
var ret = Entity.prototype.id.apply(this, arguments);
9292
if (prev == null) return ret;
@@ -106,7 +106,7 @@ User.prototype.id = function(id?: string): string | undefined {
106106
* @return {String|User}
107107
*/
108108

109-
User.prototype.anonymousId = function(anonymousId?: string): string | User {
109+
User.prototype.anonymousId = function (anonymousId?: string): string | User {
110110
var store = this.storage();
111111

112112
// set / remove
@@ -147,7 +147,7 @@ User.prototype.anonymousId = function(anonymousId?: string): string | User {
147147
}
148148

149149
// empty
150-
anonymousId = uuid.v4();
150+
anonymousId = uuidv4();
151151
store.set('ajs_anonymous_id', anonymousId);
152152
this._setAnonymousIdInLocalStorage(anonymousId);
153153
return store.get('ajs_anonymous_id');
@@ -157,7 +157,7 @@ User.prototype.anonymousId = function(anonymousId?: string): string | User {
157157
* Set the user's `anonymousid` in local storage.
158158
*/
159159

160-
User.prototype._setAnonymousIdInLocalStorage = function(id: string) {
160+
User.prototype._setAnonymousIdInLocalStorage = function (id: string) {
161161
if (!this._options.localStorageFallbackDisabled) {
162162
localStorage.set('ajs_anonymous_id', id);
163163
}
@@ -167,7 +167,7 @@ User.prototype._setAnonymousIdInLocalStorage = function(id: string) {
167167
* Remove anonymous id on logout too.
168168
*/
169169

170-
User.prototype.logout = function() {
170+
User.prototype.logout = function () {
171171
Entity.prototype.logout.call(this);
172172
this.anonymousId(null);
173173
};
@@ -176,7 +176,7 @@ User.prototype.logout = function() {
176176
* Load saved user `id` or `traits` from storage.
177177
*/
178178

179-
User.prototype.load = function() {
179+
User.prototype.load = function () {
180180
if (this._loadOldCookie()) return;
181181
Entity.prototype.load.call(this);
182182
};
@@ -187,7 +187,7 @@ User.prototype.load = function() {
187187
* @api private
188188
*/
189189

190-
User.prototype._loadOldCookie = function(): boolean {
190+
User.prototype._loadOldCookie = function (): boolean {
191191
var user = cookie.get(this._options.cookie.oldKey);
192192
if (!user) return false;
193193

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"package-json-versionify": "^1.0.4",
6060
"segmentio-facade": "^3.2.7",
6161
"spark-md5": "^2.0.2",
62-
"uuid": "^3.4.0"
62+
"uuid": "^8.0.0"
6363
},
6464
"devDependencies": {
6565
"@codeceptjs/mock-request": "^0.3.0",

0 commit comments

Comments
 (0)