From 0ff26d268ea48c213048c2fbf51fed56fc8a286e Mon Sep 17 00:00:00 2001 From: cajotafer <hello@cajotafer.com> Date: Fri, 27 May 2022 13:03:44 +0700 Subject: [PATCH 1/2] chore(deps): update uuid to v8 since v3.4 is deprecated --- README.md | 37 ++++++++++++++++++++----------------- lib/normalize.ts | 12 ++++++------ lib/user.ts | 22 +++++++++++----------- package.json | 2 +- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index abe403bb..08aa2be2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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('🚀'); ``` diff --git a/lib/normalize.ts b/lib/normalize.ts index 359e728b..c77fbbe7 100644 --- a/lib/normalize.ts +++ b/lib/normalize.ts @@ -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; /** @@ -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 || {}; @@ -59,7 +59,7 @@ 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]; @@ -67,7 +67,7 @@ function normalize(msg: Message, list: Array<any>): NormalizedMessage { // 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') @@ -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 { @@ -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; diff --git a/lib/user.ts b/lib/user.ts index 7a8553a9..fea8e6b5 100644 --- a/lib/user.ts +++ b/lib/user.ts @@ -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'); /** @@ -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', + }, }; /** @@ -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; @@ -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 @@ -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'); @@ -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); } @@ -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); }; @@ -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); }; @@ -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; diff --git a/package.json b/package.json index f72842ce..a0e71579 100644 --- a/package.json +++ b/package.json @@ -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", From 52dbec448a04c7df1ada92582bef9ee52932614f Mon Sep 17 00:00:00 2001 From: cajotafer <hello@cajotafer.com> Date: Fri, 27 May 2022 14:05:55 +0700 Subject: [PATCH 2/2] docs: update history to request new version --- HISTORY.md | 4 ++++ yarn.lock | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 5d066c0b..3b5e3400 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 4.1.11 / 2022-05-27 + +- updates uuid@3.4.0 (deprecated) to uuid@8.0.0 + # 4.1.10 / 2020-04-14 - updates top-domain to 3.0.1 diff --git a/yarn.lock b/yarn.lock index ddc02b05..a6cf7eef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9739,7 +9739,7 @@ utils-merge@1.0.1: 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== @@ -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"