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

chore(deps): update uuid to v8 since v3.4 is deprecated #272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.1.11 / 2022-05-27

- updates [email protected] (deprecated) to [email protected]

# 4.1.10 / 2020-04-14

- updates top-domain to 3.0.1
Expand Down
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
⚠️ Be sure to check out the next generation of analytics.js! https://github.com/segmentio/analytics-next 🎉
⚠️ Be sure to check out the next generation of analytics.js! https://github.com/segmentio/analytics-next 🎉
If you have an existing JavaScript source with Segment, you can enable Analytics Next in the settings of the source.

# analytics.js-core
Expand Down Expand Up @@ -37,46 +37,49 @@ declare global {
```

## Using as a standalone `npm` package
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:

1- Install the dependencies
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:

1- Install the dependencies

```
yarn add @segment/analytics.js-core
yarn add @segment/analytics.js-integration-segmentio
// you may need this depending on the bundler
yarn add uuid@^3.4
yarn add uuid@^8.0.0
```

2- Import the dependencies
2- Import the dependencies

```javascript
import Analytics from "@segment/analytics.js-core/build/analytics";
import SegmentIntegration from "@segment/analytics.js-integration-segmentio";
import Analytics from '@segment/analytics.js-core/build/analytics';
import SegmentIntegration from '@segment/analytics.js-integration-segmentio';
```

3- Initialize Segment and add Segment's own integration
3- Initialize Segment and add Segment's own integration

```javascript
// instantiate the library
const analytics = new Analytics();

// add Segment's own integration ( or any other device mode integration )
// add Segment's own integration ( or any other device mode integration )
analytics.use(SegmentIntegration);

// define the integration settings object.
// Since we are using only Segment integration in this example, we only have
// define the integration settings object.
// Since we are using only Segment integration in this example, we only have
// "Segment.io" in the integrationSettings object
const integrationSettings = {
"Segment.io": {
apiKey: "<YOUR SEGMENT WRITE KEY>",
'Segment.io': {
apiKey: '<YOUR SEGMENT WRITE KEY>',
retryQueue: true,
addBundledMetadata: true
}
addBundledMetadata: true,
},
};


// Initialize the library
analytics.initialize(integrationSettings);

// Happy tracking!
// Happy tracking!
analytics.track('🚀');
```

Expand Down
12 changes: 6 additions & 6 deletions lib/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var each = require('./utils/each');
var includes = require('@ndhoule/includes');
var map = require('./utils/map');
var type = require('component-type');
var uuid = require('uuid/v4');
var { v4: uuidv4 } = require('uuid');
var md5 = require('spark-md5').hash;

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ interface NormalizedMessage {
}

function normalize(msg: Message, list: Array<any>): NormalizedMessage {
var lower = map(function(s) {
var lower = map(function (s) {
return s.toLowerCase();
}, list);
var opts: Message = msg.options || {};
Expand All @@ -59,15 +59,15 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage {
debug('<-', msg);

// integrations.
each(function(value: string, key: string) {
each(function (value: string, key: string) {
if (!integration(key)) return;
if (!has.call(integrations, key)) integrations[key] = value;
delete opts[key];
}, opts);

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

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

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

// cleanup
delete msg.options;
Expand Down
22 changes: 11 additions & 11 deletions lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var cookie = require('./cookie');
var debug = require('debug')('analytics:user');
var inherit = require('inherits');
var rawCookie = require('@segment/cookie');
var uuid = require('uuid');
var { v4: uuidv4 } = require('uuid');
var localStorage = require('./store');

/**
Expand All @@ -38,11 +38,11 @@ User.defaults = {
persist: true,
cookie: {
key: 'ajs_user_id',
oldKey: 'ajs_user'
oldKey: 'ajs_user',
},
localStorage: {
key: 'ajs_user_traits'
}
key: 'ajs_user_traits',
},
};

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ inherit(User, Entity);
* assert.notEqual(anonymousId, user.anonymousId());
*/

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

User.prototype.anonymousId = function(anonymousId?: string): string | User {
User.prototype.anonymousId = function (anonymousId?: string): string | User {
var store = this.storage();

// set / remove
Expand Down Expand Up @@ -147,7 +147,7 @@ User.prototype.anonymousId = function(anonymousId?: string): string | User {
}

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

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

User.prototype.logout = function() {
User.prototype.logout = function () {
Entity.prototype.logout.call(this);
this.anonymousId(null);
};
Expand All @@ -176,7 +176,7 @@ User.prototype.logout = function() {
* Load saved user `id` or `traits` from storage.
*/

User.prototype.load = function() {
User.prototype.load = function () {
if (this._loadOldCookie()) return;
Entity.prototype.load.call(this);
};
Expand All @@ -187,7 +187,7 @@ User.prototype.load = function() {
* @api private
*/

User.prototype._loadOldCookie = function(): boolean {
User.prototype._loadOldCookie = function (): boolean {
var user = cookie.get(this._options.cookie.oldKey);
if (!user) return false;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"package-json-versionify": "^1.0.4",
"segmentio-facade": "^3.2.7",
"spark-md5": "^2.0.2",
"uuid": "^3.4.0"
"uuid": "^8.0.0"
},
"devDependencies": {
"@codeceptjs/mock-request": "^0.3.0",
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9739,7 +9739,7 @@ [email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"

uuid@^3.0.0, uuid@^3.3.2, uuid@^3.4.0:
uuid@^3.0.0, uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
Expand All @@ -9748,6 +9748,11 @@ uuid@^3.0.1:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"

uuid@^8.0.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^8.2.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea"
Expand Down